Store Custom Data in Annotations

When adding an annotation to a document, PSPDFKit allows storing of additional data that you can specify for each annotation. This data is persistently stored along with the annotation if the annotation is stored in one of the following formats:

  1. Embedded in the PDF

  2. Instant JSON

  3. XFDF

PSPDFKit automatically handles the serialization of the custom data attached to an annotation for these formats.

Storing Custom Data

PSPDFKit for Web 2019.2 added the customData property to PSPDFKit.Annotations.Annotation. This property allows you to store an arbitrary JSON-compliant dictionary in an annotation, like so:

const updatedAnnotation = annotation.set("customData", {
  name: "Grill House",
  locations: ["Vienna", "Paris", "New York"],
  rating: 5,
  verified: true