Dealing with Large Encrypted Files

If you implement custom encryption, you should provide an object implementing the DataProviding protocol and initialize the Document using init(dataProviders:).

PSPDFKit already implements the AESCryptoDataProvider. It uses DataProviding and provides all the delegates to dynamically decrypt just the required part of the PDF on the fly. All you need to do is provide the unencrypted file size and the callbacks for direct access.

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

❗Important: You should disable the disk cache by setting its allowedDiskSpace to 0. Otherwise, it’ll essentially invalidate the benefits of encrypting the PDF.