使用 Quartz 2D 制作 PDF 注释

发布于 2024-12-18 10:22:40 字数 125 浏览 4 评论 0原文

我正在使用 Leaves 处理 PDF。我无法弄清楚如何进行注释。我没有太多使用 Quartz 2D,想要一些指导

I am working on PDFs using Leaves. I'm unable to figure out how to make annotations. I haven't used Quartz 2D much and would like some direction

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤痕我心 2024-12-25 10:22:40

添加write注释支持很困难。

Quartz 2D 在那里帮不了你。

您需要手动解析 PDF。 (例如使用 NSScanner)并构建所有 PDF 对象的 XRef 树。然后,您将编写一个新的预告片来替换 /Page 对象并附加所有新的注释数据。要做到正确是相当困难的,而且 2000 页的 PDF 参考资料对此也没有多大帮助。我在这一年中的大部分时间都在努力获得适当的注释支持(突出显示、下划线、删除线、墨迹、注释……)。

当您想要突出显示注释时,您还需要文本选择(否则用户将不得不自由绘制突出显示 - 这不是一个很好的体验。)为所有 PDF 字体类型获取正确的文本字形框架是另一个恐怖级别;在 PDF 中,没有单词或列的概念。只是单个字形。剩下的就是算法和猜测。

我什至与一些苹果工程师讨论了他们是如何做到的[文本选择、注释],他们告诉我一个三人团队花了大约三年的时间来实施。

Adding write annotation support is hard.

Quartz 2D won't help you there.

You need to manually parse the PDF. (e.g. with NSScanner) and build up the XRef tree of all the PDF objects. Then you're writing a new trailer that replaces the /Page object and attaches all new annotation data. It's quite hard to get right, and the 2000 pages PDF reference is not very helpful on that. I worked the better part of the year for proper annotation support (Highlight, Underscore, Strikeout, Ink, Note, ...).

And when you want highlight annotations, you also want text selection (else the user would have to free-draw a highlight - not a nice experience.) Getting the correct frames for the text glyphs for all PDF font types is another level of horror; in PDF there's no notion of a word or a column. Just single glyphs. The rest is algorithms and guessing.

I even spoke with some Apple engineers how they did it [text selection, annotations], and they told me a three-person team worked about three years on their implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文