问题
Is there any way to create PDF objects (e.g. a PDF-dictionary with parameters that are needed by a custom PDF producer/consumer/viewer) with CGPDF<...> or do I have to write my own parser and create new trailers, xref etc. in order to add new objects to the PDF? As I understand it, CG translates all drawing calls of its graphics context into the correct PDF counterparts when creating a PDF - but I have custom data/objects (e.g. for annotations, threads etc.) that should be stored in the PDF but that obviously can't be automatically created by CG.
I can only find all these getters
Getting Data from a Dictionary
CGPDFDictionaryGetArray
CGPDFDictionaryGetBoolean
CGPDFDictionaryGetCount
CGPDFDictionaryGetDictionary
CGPDFDictionaryGetInteger
CGPDFDictionaryGetName
CGPDFDictionaryGetNumber
CGPDFDictionaryGetObject
CGPDFDictionaryGetStream
CGPDFDictionaryGetString
Any help would be appreciated ?
And by the way - does anyone know some links where I can find out what one can achieve in the real world with this function and its callback.
CGPDFDictionaryApplyFunction
CGPDFDictionaryApplierFunction
Maybe a sample application to see it in action?
Thx in advance
回答1:
There are no setters. The CGPDF API is read only.
The CGPDFDictionaryApplyFunction simply lets you enumerate the entries in a dictionary object. The PDFKitten framework uses this function in a few places if you want to see real world usage.
回答2:
We found that out the hard way when we added annotation support in the commercial PSPDFKit SDK for iOS and Android.
Check out the PDF Specification, Page 23ff for a list of standard filters you need to support, next to a simple lexer/parser.
We built the initial version in Objective-C, using raw file access and then using our own small parser. Once you have all objects parsed you can append a new trailer with the objects you want to change. Without support for all of the above compression methods this will not work for all documents though. It took a few years to get to a state where we can say that it works with 99.9% of all documents out there. There's the PDF spec and then there's the reality with files out there that should not be working in any sane renderer, yet Adobe Acrobat happily renders the document. PDF in that is more like HTML, where even when things are terrible and broken, browsers still show something.
We ended up re-implementing everything in C++ to achieve great parsing performance and have thousands of tests for this component alone. You can also look into other commercial products such as muPDF that might help you - I just want to save you from going down the path of re-implementing everything from scratch, as it will simply take a few years to get the code to an acceptable level of compatibility and performance.
来源:https://stackoverflow.com/questions/31497910/cgpdf-where-are-the-setters