如何在iOS上的PDF中检索“大纲”目标的页码或页面引用? [英] How do I retrieve a page number or page reference for an Outline destination in a PDF on iOS?

查看:507
本文介绍了如何在iOS上的PDF中检索“大纲”目标的页码或页面引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读adobe pdf规范,以及用于pdf渲染和解析的apple的quartz 2d文档。我还下载了Voyeur,并用它查看了本地pdf以查看它的内部数据。此时我可以获取文档目录,然后从那里获取轮廓字典。我可以看到嵌套在轮廓词典词典中的是名为/ Dest的节点,其值如下:

I've been reading through the adobe pdf spec, along with apple's quartz 2d documentation for pdf rendering and parsing. I've also downloaded Voyeur and inspected a local pdf with it to see it's internal data. At this point I'm able to get the document catalog, and then fetch the outlines dictionary from there. I can see that nested within the outlines dictionary dictionaries that there are named "/Dest" nodes with values such as:

G1.1025588
etc

G1.1025588 etc

我想知道是否有办法让我使用这些值来获取对页面的引用,使用一些方法来渲染我已经看过github项目,如Reader,以及苹果记录的例子。

I'm wondering if there is a way for me to use these values to get a reference to page to render using some methods I've seen github projects such as Reader, along with apple documented examples.

PDF处理绝对是一个挑战,所以任何帮助都会受到赞赏。

PDF processing is definitely a challenge, so any help would be appreciated.

推荐答案

大纲项目词典中的 / Dest 条目可以是名称字符串,或者数组

The /Dest entry in an outline item dictionary can either be a name, a string, or an array.


  • 最简单的情况是,如果它是数组 ;然后第一项是大纲条目指向的页面对象(字典)。要获取页码,您必须遍历文档中的所有页面,并查看哪个页面相等( == )到您拥有的词典( CGPDFPageRef s实际上是 CGPDFDictionaryRef s)。你也可以遍历页面树,这有点难,但可能更快(没有你想象的那么多,我不会在这里过早优化)。数组中的其他项目位于页面等位置,在PDF规范中搜索显式目的地以了解更多信息。

  • The simplest case is if it's an array; then the first item is the page object the outline entry points to (a dictionary). To get the page number, you have to iterate over all pages in the document and see which one is equal (==) to the dictionary you have (CGPDFPageRefs are actually CGPDFDictionaryRefs). You could also traverse the page tree, which is a bit harder, but may be faster (not as much as you might expect, I wouldn't optimize prematurely here). The other items in the array are position on the page etc., search for "Explicit Destinations" in the PDF spec to learn more.

如果条目是名称字符串,它是指定目的地。您必须从文档目录的 / Dests 条目将名称映射到目标,该条目是包含名称树的字典。名称树本质上是一个树映射,允许快速访问命名值,而无需一次读取所有数据(与普通字典一样)。不幸的是,在Quartz中没有对名称树的直接支持,所以你需要做更多的工作来递归地解析这个结构(参见 PDF规范)。

If the entry is a name or string, it is a named destination. You have to map the name to a destination from the document catalog's /Dests entry which is a dictionary that contains a name tree. A name tree is essentially a tree map that allows fast access to named values without requiring to read all the data at once (as with a plain dictionary). Unfortunately, there's no direct support for name trees in Quartz, so you'll have to do a little more work to parse this structure recursively (see "Name Trees" in the PDF spec).

请注意,大纲项目不一定具有 / Dest 条目,它还可以通过<$ c $指定其目的地c> / A (动作)条目,这有点复杂。但是,在大多数情况下,操作将是一个GoTo操作,它本质上是目标的包装。

Note that an outline item doesn't necessarily have a /Dest entry, it can also specify its destination via an /A (action) entry, which is a little bit more complex. In most cases, however, the action will be a "GoTo" action that is essentially a wrapper for a destination.

名称到目标的映射也可以存储为一本普通的字典。在这种情况下,它位于文档目录中/ Names字典的 / Dests 条目中。我很少看到这个,它在PDF 1.2(当前为1.7)之后被弃用。

The mapping of names to destinations can also be stored as a plain dictionary. In that case, it's in the /Dests entry of the /Names dictionary in the document's catalog. I've rarely seen this though and it was deprecated after PDF 1.2 (current is 1.7).

你肯定需要PDF规范: http://www.adobe.com/content/dam/Adobe/ en / devnet / pdf / pdfs / PDF32000_2008.pdf

You will definitely need the PDF spec for this: http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf

这篇关于如何在iOS上的PDF中检索“大纲”目标的页码或页面引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆