Save PDF Annotations in iOS

PSPDFKit supports various ways to save edits to a document’s annotations. Annotations can be embedded in a PDF or saved to an external file, either in a format defined by PSPDFKit or in your custom format.

By default, the annotationSaveMode of Document is set to .embeddedWithExternalFileAsFallback. This means PSPDFKit will analyze a PDF and see if it can write annotations into it, and if that fails, an external file format will be used to save annotations.

PSPDFKit can write annotations into a PDF under the following conditions:

  • The PDF must be in a writable location. This is pretty much every folder except the application bundle folder, since that one is signed. If you prepopulate PDFs with your app, they’ll be in the app bundle and thus not writable. Copy them to the documents folder to make them writable.

  • The PDF must be valid according to the Adobe PDF specification. Some PDFs are broken but still work somewhat, so PSPDFKit can render the content. If PSPDFKit detects a mismatch in the object tree or is unable to find objects, annotation saving will be stopped, since there would be a risk of damaging the document.

If annotations can’t be saved, PSPDFKit uses an internal file format with the default location in /Library/PrivateDocuments/annotations.pspdfkit. This file is only intended for internal use. Don’t upload this to your web server, as the file format is subject to change.

PSPDFKit will save “dirty” (changed/created/deleted) annotations on several occasions. Learn more about these triggers here.

Read more about annotation providers here.