How to convert from pixels to millimeters

I am working with PHP and FPDF to generate a PDF invoice. The designers have created a couple of very helpful documents, there are three total. The first is a mockup of the invoice. The second shows fonts, font sizes, and font colors. The last document show the positioning of all elements on the invoice. My only problem, is that the document was made with pixels at a resolution of 300 DPI rather than in millimeters. Anyone that is familiar with FPDF will know that PDF’s created with FPDF can not be generated with pixels in mind. PDF documents in FPDF can only use point (pt), millimeteres (mm), centimeters (cm), or inches (in).So I needed to come up with a way to convert things to what I needed them to be. Here is the solution I came up with. First, we need to discuss the conversion factors. My document had a DPI of 300, DPI stands for Dots Per Inch. This means that in every in there are 300 pixels. But we aren’t using inches for measurements on the document, we are using millimeters. Well, there are 25.4 millimeters in an inch. So, how do we go all the way from pixels to millimeters. Simple.

In chemistry, we studied something called dimensional analysis. Dimensional analysis is a method for converting from one unit to another. So first off we multiply the number of pixels by 1 over our DPI (in this case 300 DPI) then we multiply that by 25.4 by one inch (number of millimeters in an inch) Once everything cancels out we are left with a fairly nice, simple and easy to use formula.
mm = (pixels * 25.4) / dpi
In order to convert back from millimeters to pixels we simply reverse the formula using simple algebra.
pixels = (mm * dpi) / 25.4
There you have it. A very simple way to convert from pixels to millimeters. And then from millimeters back to pixels.

13 Responses to “How to convert from pixels to millimeters”

  1. Nikkdawg says:

    So thats what they were talking about during my morning chemistry nap, very impressive. Heck, just the fact that you can remember terms like dimensional analysis is impressive. Now, see if you can use “dimensional analysis” to convert my wasted hours in chemistry class into future dollors lost.

  2. TOMiD says:

    Thanks :-) .

  3. bokohod says:

    Very useful. Thanks.

  4. Chris says:

    Good article, thanks. I’m a developer and i’m developing a label creator where users can select an image add some text and create a pdf of labels to print, i’m using the fpdf library but after doing my image conversions from pixels for the image to be displayed on the website to mm’s to be displayed on the pdf.

    This all works fine as the labels fit the right sizes the prob i’m having is that the image is showing a lot smaller on the web, and with users needing to set their overflow text this is proving a prob. Any advice on this? my conversions are correct as your formula gives me the same results as the conversion calcs i’ve used. /the dpi is set to 72, i dont know if that has anything to do with it as i have no knowledge of dpi’s

    Thanks

  5. Sharmila says:

    Useful article, thanks.

  6. Jason says:

    Thanks, this is exactly what I was looking for. Very helpful.

  7. Me says:

    But a pixel has NO measurement.

  8. I simply could not leave your web site before suggesting
    that I really loved the usual info a person provide in your visitors?
    Is going to be back steadily in order to check
    out new posts

  9. With havin so much content and articles do you ever run into any problems of plagorism or copyright violation?
    My blog has a lot of exclusive content I’ve either created myself or outsourced but it seems a lot of it is popping it up all over the internet without my agreement. Do you know any techniques to help reduce content from being stolen? I’d definitely
    appreciate it.

  10. With these new mortgage normals in stead and see your doc for these ellwood
    harms? In India, English, Hindi, Punjabi and regional ellwoodpapers ply
    the environmental clauses feature represented about solar
    or weave vigor. Every thing we do is intentional to induce
    your automobile ellwood seek intervention with for these traumas?

  11. jrard says:

    Hey Hi,
    Nice little conversion there. So will this work in 3D Laser Scanning in which I want to estimate the dimensions of the scanned 3D object?

  12. To convert from Pixel to mm in a PDF file you need this Php Function:
    function toMM($v) {
    return ($v * 26.2) / 25.4;
    }

    26.2 is my magic dpi Number ;)

  13. Katherina says:

    I see a lot of interesting content on your
    website. You have to spend a lot of time writing, i know how
    to save you a lot of time, there is a tool that creates
    unique, SEO friendly articles in couple of
    seconds, just type in google – k2 unlimited content

Leave a Reply


Switch to our mobile site