Suhas Bhattu
Suhas Bhattu

Reputation: 551

Different height and width property for PDF File in PDFBox

For a certain PDF file if I use page.getMediaBox().getWidth() and page.getMediaBox().getHeight() to get width and height of PDF file page using PDFBox, if shows values which are different than the values I am getting using the PDFBoxDebugger. What might be the reason? I am attaching the screenshot for the PDFDebugger. I am using PDFBox-2.0.9 version. The values I am getting from page.getMediaBox().getWidth() and page.getMediaBox().getHeight() are 531.36597 and 647.99603 respectively which do not match with the PDFBoxDebugger values. (And it only occurs for the first page of PDF, for further pages it works fine)

MediaBox shows different values than the values using the MediaBox() method

Upvotes: 0

Views: 1166

Answers (1)

mkl
mkl

Reputation: 95918

As Tilman already stated in a comment, the values to expect are

  • a width of 1282.2 - 750.834 = 531.366 and
  • a height of 849.593 - 201.597 = 647.996 (corrected value).

The observed values

531.36597 and 647.99603

correspond to the expected values well enough considering the accuracy of the float type.


I assume the op misunderstands the values of the MediaBox array. They do not contain the width or height as explicit values but the coordinates of two opposite corners of the box.

The MediaBox value is specified to have the type rectangle, cf. ISO 32000-1 table 30 Entries in a page object. And a rectangle is specified as

a specific array object used to describe locations oon a page and bounding boxes for a variety of objects and written as an array of four numbers giving the coordinates of a pair of diagonally opposite corners,

cf. ISO 32000-1 section 4.40 rectangle.


As also already mentioned by Tilman you probably should be looking at the CropBox instead.

Upvotes: 2

Related Questions