Solved

# Convert mm to pixel

Posted on 2007-07-25
32,415 Views
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
Question by:kristian_gr

LVL 92

Expert Comment

depends on the dpi you want to display it as

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

LVL 23

Expert Comment

The approx conversion is

1pxl = 0.3125 mm
0

LVL 37

Expert Comment

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

LVL 14

Accepted Solution

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

### Suggested Solutions

Using object mapper in spring web application 8 39
countClumps  challenge 10 70
noX challenge 17 55
@SBGen Method 3 17
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…