Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to calculate PDF image dpi

1 min read

How to calculate PDF Image dpi

Most elements of a PDF file are device independent Vector graphics. This means that they will always appear ‘smooth and clear’. By contrast images are bit-mapped. If the image is stretched it can appear pixellated. If the image is too small, it will be stretched and the pixels will become blocky. This happens when the image is of a low resolution.

There is a tradeoff here. The better quality, the bigger it (and the PDF) will be. That is why most PDF creation tools allow you to specify whether you are producing files for screen or printing. Printing benefits from better images but this means bigger files.

What you actually have with a PDF file is a raw image and a ‘scaling’ command to fit it into a slot on the page (the CTM matrix). If the raw image is bigger than the ‘slot’ you can zoom into the page and print it at high resolution. But there drawbacks. We saw a very large PDF file with raw images of 26,000 x 26,000 pixels which is rather excessive!

Combining the raw image size and the CTM does actually allow you to work out the image quality to decide how well the PDF file will scale and fit. Let me show you with an example. Imagine we have an image which is 585×585 pixels. It is shown on page with this CTM value.

(843 0 0)

(0 843 0)

(x y 1)

We can work out the dpi value with this formula

dpi =(int)(imageWidth/GraphicsStateValue*100);

This gives us a value of 69. This is reasonable for screen display (where 72 is the target figure) but not great for printing or for fine zooming. For printing, 300+ dpi should be the target.

We have added dpi calculations into our PDF viewer so you can get JPedal to do all the hard work of calculating the dpi with the 20th December release.



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.