Flattening Annotations in PDFs

When flattening an annotation, the annotation is removed from the document, while its visual representation is kept intact. A flattened annotation is still visible but no longer editable by your users or your app. This can be used, for example, to permanently apply annotations to your document, or to make annotations visible to viewers that otherwise can’t show annotations (like Safari on iOS).

There are two ways to flatten annotations in a PDF with PSPDFKit:

  • Using the Document Editor

  • During export

Using the Document Editor

This method only works if you have the Document Editor component in your license. You can flatten the annotations using PSPDFKit.Instance#applyOperations(operations). If the pageIndexes property is provided, the operation will only affect annotations on the specified pages:

instance.applyOperations([
  {
    type: "flattenAnnotations",
    pageIndexes: [0]
  }
]);

During Export

You can use Instance#exportPDF() to flatten annotations during export:

const content = await instance.exportPDF({ flatten: true });
console.log(content); // => ArrayBuffer