How to get the image DPI in PDF?

I'm trying to get information about scanned images that are saved into PDF files through iText (using Java). I can get width and height (either through Matrix, or through BufferedImage). The idea wa

I'm trying to get information about scanned images that are saved into PDF files through iText (using Java). I can get width and height (either through Matrix, or through BufferedImage). The idea was to use the answer here to calculate the DPI, but I am a bit lost. Are these values (width and height) in pixels or points? Is there any other way to achieve this? There are a lot of answers on how to scale and save an image to a PDF file, but I didn't find any on how to read the width/height/scale of an image and be confident about the result.

Posted on StackOverflow on Aug 28, 2014 by Finik

Now you don’t need to calculate the DPI values yourself. There is an ImageData class in iText 7 with built-in methods to solve your problem:

ImageData image = ImageDataFactory.create(IMG);
int x = image.getDpiX();
int y = image.getDpiY();

Click this link if you want to see how to answer this question in iText 5.


Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now