Skip to main content

Working with Annotations

Annotations can be read from, and written to, a MuPDF document instance. In this way a developer is able to separately store annotations and programmatically manage them.

Annotation data format

Annotations are read and written to the MuPDF WebViewer in a JSON format, referenced as Annotation[] the format is as follows:
The data within each object is dependent on the annotation type, for example a highlight annotation might be as follows: Example

Reading annotation data

To read annotation data from a document we use the annotation.get() method. Once we have the data we can work with it just as we would with any JSON object. Example

Writing annotation data

To write annotation data to a document we use the annotation.add() method. For example, to write annotations to the document from JSON data stored in local storage we could do the following: Example
Or to add a note annotation to a document we might do: Example

Removing annotation data

Annotations can be removed from a document by using the annotation.remove() method. To remove an annotation, provide either its oid (unique across the document) or its name and pageIndex (since name is only unique within a page). Example

Setting the Annotation Author

When creating annotations in MuPDF WebViewer you can predefine the author of the annotation by listening to the ANNOTATION_CREATE event and then setting the annotation metadata for the author name. Example