Java
--
Questions
--
Followers
Top Experts
Convert mm to pixel
Hi.
I need a method to convert milimeter to pixel.
I'm using the iText to generate pdf'docs. When I set the document size I need a com.lowagie.text.Rectangle Object.
The Rectangle takes float width, float height as arguments and I guess it is pixel.
I only have the correct  messures for the file I need to create in mm.
Any Idea how to do this?
I need a method to convert milimeter to pixel.
I'm using the iText to generate pdf'docs. When I set the document size I need a com.lowagie.text.Rectangle
The Rectangle takes float width, float height as arguments and I guess it is pixel.
I only have the correct  messures for the file I need to create in mm.
Any Idea how to do this?
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
depends on the dpi you want to display it as
mm = 254 * pixels / dpi;
pixels = (mm * dpi) / 254
mm = 254 * pixels / dpi;
pixels = (mm * dpi) / 254
The approx conversion is
1pxl = 0.3125 mm
1pxl = 0.3125 mm
I think the correct formula is:
 pixels = (mm * dpi) / 25.4
Let me explain a little bit.
1 inch = 25.4 mm
If we assume a resolution of e.g. 300 dpi (that's 300 dots or pixels per inch)
then 100 mm (being approx. 4 inches) is 300*4 = 1200 pixels
The formula gives:
100 * 300 / 25.4 = 1181 pixels
 pixels = (mm * dpi) / 25.4
Let me explain a little bit.
1 inch = 25.4 mm
If we assume a resolution of e.g. 300 dpi (that's 300 dots or pixels per inch)
then 100 mm (being approx. 4 inches) is 300*4 = 1200 pixels
The formula gives:
100 * 300 / 25.4 = 1181 pixels






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.