Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read resolution of a pdf in pdf box

Tags:

java

pdf

pdfbox

I am able to convert the PDF pages into individual images. But I want to read the resolution (dpi), length and height of the PDF before converting to images. Please, how to know these metadata of the PDF in Java using pdfbox?

like image 390
user1955041 Avatar asked Dec 06 '25 02:12

user1955041


1 Answers

Generally: Pdf is vector-based, so there is no fixed resolution. You can render it in any resolution.

But there is a way to get the information you want. Following method returns a dimension of the page:

PDRectangle cropBox = page.findCropBox();
Dimension dimension = cropBox.createDimension();

By comparing this dimension with the size of a document (AdobeReader -> File -> Properties), it looks like the default dpi is 72. With this information you can calculate the width and height of the page.

like image 56
user1958676 Avatar answered Dec 07 '25 17:12

user1958676



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!