Convert mm to pixel

Posted on 2007-07-25
Last Modified: 2010-05-28
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?
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
    LVL 23

    Expert Comment

    The approx conversion is

    1pxl = 0.3125 mm
    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
    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.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    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…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now