I have a NSMutableData object which contains a PDF file. I know how to open an PDF stored on the system, which can me done like this:
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)pathToPDF, NULL, NULL);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
But now I don’t want to store the file on the system, but create the PDF object on the fly (because the PDF is stored on the system as an encrypted PDF, and I don’t want to save the decrypted file for security reasons.)
So instead of loading the CGPDFDocumentRef pdf from a file, I want to directly load it from an NSMutableData object.
How can I do this?
Thanks in advance!
Use
CGDataProviderto get bytes from an arbitrary source:You could also create an instance of
CGDataProviderthat decrypts on-the-fly using callbacks, if that fits your flow better. See the documentation for details.