user1955041
user1955041

Reputation: 35

how to read resolution of a pdf in pdf box

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?

Upvotes: 3

Views: 4889

Answers (1)

user1958676
user1958676

Reputation: 61

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.

Upvotes: 3

Related Questions