PDFBox 中 PDF 文件的不同高度和宽度 属性

Different height and width property for PDF File in PDFBox

对于某个 P​​DF 文件,如果我使用 page.getMediaBox().getWidth()page.getMediaBox().getHeight() 使用 PDFBox 获取 PDF 文件页面的宽度和高度,如果显示的值与我使用的值不同PDFBoxDebugger。可能是什么原因?我附上 PDFDebugger 的屏幕截图。我正在使用 PDFBox-2.0.9 版本。我从 page.getMediaBox().getWidth()page.getMediaBox().getHeight() 得到的值分别是 531.36597 和 647.99603,它们与 PDFBoxDebugger 值不匹配。 (而且它只发生在 PDF 的第一页,对于更多页面它工作正常)

正如 Tilman 已在评论中所述,预期的值为

  • 宽度为 1282.2 - 750.834 = 531.366
  • 身高 849.593 - 201.597 = 647.996(修正值)。

观测值

531.36597 and 647.99603

考虑到 float 类型的准确性,

与预期值足够吻合。


我假设操作误解了 MediaBox 数组的值。它们不包含作为显式值的宽度或高度,而是 盒子的两个相对角的坐标

MediaBox 值被指定为 rectangle 类型,参见。 ISO 32000-1 table 30 页面对象中的条目矩形被指定为

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,

比照。 ISO 32000-1 第 4.40 节 矩形.


正如 Tilman 已经提到的,您可能应该查看 CropBox