Dealing with Large Encrypted Files

If you implement custom encryption, you should provide a object implementing the PSPDFDataProvider protocol and initialize the PSPDFDocument using documentWithDataProvider:.

PSPDFKit already implements the PSPDFAESCryptoDataProvider. It uses PSPDFDataProvider internally and provides all the delegates do dynamically decrypt just the required part of the PDF on the fly. You just provide the unencrypted file size and the callbacks for direct access.

The naive approach to this would be using NSData, but this is limited to the amount of available memory, and generally not a good idea once your documents are above 20 MB.

Careful: You should also set the diskCacheStrategy to PSPDFDiskCacheNothing, otherwise the disk cache will pretty much invalidate any encryption you're having.

Was this page helpful? We're happy to answer any questions.