Embed Annotations in a PDF File on Android

By default, PSPDFKit will save annotations into a PDF as long as the file is writable. This means the annotations are embedded into the PDF document file as annotation objects that can be edited and removed when the file is opened again in a reader that supports annotation editing. If you want to flatten the annotations so they are uneditable, see the annotation flattening 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. If auto saving is enabled, there’s nothing more to do; all annotations will automatically be saved in the PDF on an autosave event. See the Auto Save guide for more information. If you have auto save disabled, annotations will be embedded when calling the save (or saveIfModified) method of the PdfDocument class.

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 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 annotations to an external source for more details.