How can I read-modify-write a PDF (CGPDFDocument) on iOS?

馋奶兔 提交于 2019-12-06 02:57:53

I'm not aware of a way with CoreGraphics than to iterate over each page and print them into the new document. At least that's what I'm doing in PSPDFKit. And re-rendering a whole document is quite slow for larger documents.

You also loose some metadata when you go that way - maybe a much more direct manipulation of the PDF is a better way - but note that you need to update the xref trailer in the PDF if you directly edit strings, since the trailer is a map of byte-coordinates that will change once you add/delete characters.

Don't use CGPDFDocument (Core Graphics); use PDFDocument (PDFKit) instead. That provides much easier methods for this kind of thing.

The writeToFile:withOptions method lets you save the PDF to a new file, specifying the DOCINFO data in a dictionary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!