Embed Annotations in PDF on iOS
By default, PSPDFKit will save annotations into a PDF as long as the file is writable. If that isn’t possible, then an external file format will be used to save annotations. For more details, please refer to our overview guide.
How to Embed Annotations into a PDF File
To embed saved annotations into a PDF, make sure the PDF file you’re opening is valid and in a writable file system location (not in the app bundle). Then, set the annotationSaveMode
property to .embedded
, like so:
let document = ...
document.annotationSaveMode = .embedded
If you’re using the embedded save mode and the file isn’t writable, annotation editing will be disabled in the PSPDFKit UI.
The Benefits of Embedding Annotations into a PDF File
Saving annotations embedded in a PDF file has the benefit of having a single file with all its annotations in it. Embedding annotations into a PDF is helpful for scenarios like sharing, because you can share the PDF file with other users who use different PDF viewing applications. Since there’s a single source of truth, embedding annotations in the PDF is the best option when also using the Document Editor, because the annotations will be preserved as expected when performing operations like reordering pages or duplicating pages.
However, for some use cases where you need to save and store annotations outside a PDF file — say in a database — you may want to save annotations outside the PDF. Please refer to our guide about saving and storing annotations to external storage for more details.