Link to home
Create AccountLog in
Java

Java

--

Questions

--

Followers

Top Experts

Avatar of kristian_gr
kristian_gr🇳🇴

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?

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Mick BarryMick Barry🇦🇺

depends on the dpi you want to display it as

mm = 254 * pixels / dpi;
pixels = (mm * dpi) / 254

Avatar of Siva Prasanna KumarSiva Prasanna Kumar🇮🇳

The approx conversion is

1pxl = 0.3125 mm

Avatar of zzynxzzynx🇧🇪

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

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


ASKER CERTIFIED SOLUTION
Avatar of CPColinCPColin🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account
Java

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.