在 iPhone 操作系统上保存通过 PDF 渲染的 Quartz 绘图
在我的应用程序中,我正在显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题:
解决方案:
保存 PDF 页面引用就像保存与 PDF 和当前页面关联的 URL 一样简单。
保存绘图指令就像归档用作绘图指令的
UIBezierPath
一样简单,因为UIBezierPath
符合NSCoding
。如果您使用CGMutablePathRef
,则可以从CGPath
初始化UIBezierPath
并存档新初始化的贝塞尔曲线路径。解压后,您可以从UIBezierPath
检索CGPath
。如果您不需要用户能够在接下来的会话中编辑绘图指令,那么您可以将绘图渲染为静态图像,然后在下次加载并绘制该图像。该会话结束后,在原始图像上渲染这些指令,将其保存,然后像以前一样继续。
Problem:
Solution:
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
UIBezierPath
s used as the drawing instructions, sinceUIBezierPath
conforms toNSCoding
. If you're usingCGMutablePathRef
instead, you could initialize aUIBezierPath
from theCGPath
and archive the newly initialized bezier paths. You can retrieve theCGPath
from theUIBezierPath
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.