Storing Custom Data in an Annotation

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

Copy
1
2
3
4
5
6
7
8
const updatedAnnotation = annotation.set("customData", {
  name: "Grill House",
  locations: ["Vienna", "Paris", "New York"],
  rating: 5,
  verified: true
});

instance.updateAnnotation(updatedAnnotation);