• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 33616
  • Last Modified:

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?
0
kristian_gr
Asked:
kristian_gr
1 Solution
 
objectsCommented:
depends on the dpi you want to display it as

mm = 254 * pixels / dpi;
pixels = (mm * dpi) / 254
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
The approx conversion is

1pxl = 0.3125 mm
0
 
zzynxSoftware engineerCommented:
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
0
 
CPColinCommented:
iText uses PostScript points as its measurement. Google reports these values for conversion:

1 PostScript point = 0.352777778 millimeters
1 millimeter = 2.83464567 PostScript points
1 inch = 72 PostScript points
1 inch = 25.4 millimeters

You should be able to get some conversions out of that.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now