从 PDF link 的矩形计算的负高度

Negative height calculated from a PDF link's Rect

我正在努力从 PDF 文档中提取 link 和他们的位置。

每个 link 都有一个边界矩形。

<</A 169 0 R/BS<</S/S/Type/Border/W 0>>/Border[0 0 0]/H/N/Rect[97.0153 116.556 185.543 21.5209]/Subtype/Link/Type/Annot>>

我们来看一下Rect[97.0153 116.556 185.543 21.5209](我是从我的文件里复制过来的)

Rectangle is an array of four numbers in default user space units giving the coordinates of the left, bottom, right and top edges respectively.

所以我们有 left = 97.0153bottom = 116.556right = 185.543top = 21.5209

据我所知PDF的用户space是正笛卡尔坐标系。所以, 我希望矩形的上边缘大于底部的边缘,所以当我想计算矩形的高度时,我使用公式 height = top - bottom。对于那个特定的 PDF 文档 height = 21.5209 - 116.556 = -95.036,即高度为负,我做错了。

我一定是漏掉了什么,做出了错误的假设。请问有人可以指教吗?

关于你的性格

Rectangle is an array of four numbers in default user space units giving the coordinates of the left, bottom, right and top edges respectively.

你在评论中说

I got it from BBox entry description, too. BBox is declared to have type rectangle and provided with description if rectangle. PDF Rfeference, 3rd edition, p. 616.

但是BBox入口描述并不是rectangle类型的definition定义 在第 101 页:

3.8.3 Rectangles

Rectangles are used to describe locations on a page and bounding boxes for a variety of objects, such as fonts. A rectangle is written as an array of four numbers giving the coordinates of a pair of diagonally opposite corners. Typically, the array takes the form

[llx lly urx ury]

specifying the lower-left x, lower-left y, upper-right x, and upper-right y coordinates of the rectangle, in that order.

Note: Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners. Applications that process PDF should be prepared to normalize such rectangles in situations where specific corners are required.

因此,您为 BBox 条目找到的特征使得该 BBox[=] 所需的 typical 形式41=]条目。但是,其他矩形可能仍使用非典型形式。因此,您需要对数组进行归一化(或者在您的情况下,将该差异的绝对值作为高度)。

顺便说一句,我也不指望 BBox 条目总是采用 typical 形式。随时准备规范化矩形数组。


也就是说,您应该帮自己一个忙,不要再使用 2001 年的旧 PDF 参考,而是使用指定 PDF 的 ISO 规范,即 ISO 32000-1 或 ISO 32000-2。 ISO 32000-1 已于 2008 年发布。ISO 32000-2 已于 2017 年发布并于 2020 年更新。

如果您不想在规范上花钱,Adobe 已在其网站上共享了 ISO 32000-1 的副本,其中删除了 ISO 页眉。要找到它,只需搜索“PDF32000”;目前它在 https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf

仍应使用 PDF 1.4 参考的唯一情况是在基于该参考的规范的上下文中,例如PDF/A-1。否则 PDF 参考已经过时,并且之前已经被 Adob​​e PDF 架构师 Leonard Rosenthol 称为本质上不规范