在 iPhone 操作系统上保存通过 PDF 渲染的 Quartz 绘图

发布于 2024-09-13 06:24:47 字数 160 浏览 3 评论 0原文

在我的应用程序中,我正在显示 PDF 页面,并希望允许用户通过在页面顶部徒手绘制来“标记”文档。我可以处理 Quartz 代码来进行徒手绘图,但是我可以使用什么方法来保存这些“标记”,以便下次用户将 PDF 加载到应用程序中时可以在页面上重新显示它们?

谢谢,

//斯科特

In my app I am displaying PDF pages and want to allow the user to "mark up" the document by freehand drawing on top of the page. I can handle the Quartz code for doing the freehand drawing, but what approach can I used to save these "mark ups" so that they can be re-displayed over the page the next time the user loads the PDF into the app?

Thanks,

//Scott

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

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

发布评论

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

评论(1

箹锭⒈辈孓 2024-09-20 06:24:47

问题:

  • 给定一个 PDF 页面和一系列绘图指令,
  • 应用应该能够
  • 应用时 重复该页面的这些绘图指令在接收绘图指令和查看页面之间已退出。

解决方案:

  • 将对 PDF 页面的引用和绘图说明保存到持久存储中。
  • 加载所查看页面的绘图说明。
  • 渲染绘图指令。

保存 PDF 页面引用就像保存与 PDF 和当前页面关联的 URL 一样简单。

保存绘图指令就像归档用作绘图指令的 UIBezierPath 一样简单,因为 UIBezierPath 符合 NSCoding。如果您使用 CGMutablePathRef,则可以从 CGPath 初始化 UIBezierPath 并存档新初始化的贝塞尔曲线路径。解压后,您可以从 UIBezierPath 检索 CGPath

如果您不需要用户能够在接下来的会话中编辑绘图指令,那么您可以将绘图渲染为静态图像,然后在下次加载并绘制该图像。该会话结束后,在原始图像上渲染这些指令,将其保存,然后像以前一样继续。

Problem:

  • Given a PDF page and a series of drawing instructions,
  • the app should be able to repeat those drawing instructions for that page
  • when the app has been quit in between receiving the drawing instructions and viewing the page.

Solution:

  • Save a reference to the PDF page and the drawing instructions to persistent storage.
  • Load the drawing instructions for the viewed page.
  • Render the drawing instructions.

Saving the PDF page reference could be as simple as saving the URL associated with the PDF and the current page.

Saving the drawing instructions could be as simple as archiving the UIBezierPaths used as the drawing instructions, since UIBezierPath conforms to NSCoding. If you're using CGMutablePathRef instead, you could initialize a UIBezierPath from the CGPath and archive the newly initialized bezier paths. You can retrieve the CGPath from the UIBezierPath after unarchiving.

If you do not need the user to be able to edit the drawing instructions on the following session, then you could render the drawing to a static image and just load and draw that the next time. After that session, render those instructions over the original image, save that out, and continue as before.

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