Manage annotations effectively with our API

In addition to managing annotations with the create, update, and delete APIs, we also provide events that let you intercept annotation changes made through the user interface (UI) or synced from the server.

EventUse case
annotations.loadTriggered when annotations are loaded from the document.
annotations.willChangeTriggered before a user modifies an annotation through the UI (for example, by drawing).
annotations.changeTriggered when annotations change due to a user action or API call.
annotations.createTriggered when new annotations are created.
annotations.updateTriggered when existing annotations are updated.
annotations.deleteTriggered when annotations are deleted.
instance.addEventListener("annotations.load", loadedAnnotations => {
console.log(loadedAnnotations);
});
instance.addEventListener("annotations.willChange", event => {
if (event.reason === PSPDFKit.AnnotationsWillChangeReason.DRAW_START) {
console.log("The user is drawing...");
}
});
instance.addEventListener("annotations.change", () => {
console.log("Something in the annotations has changed.");
});
instance.addEventListener("annotations.create", createdAnnotations => {
console.log(createdAnnotations);
});
instance.addEventListener("annotations.update", updatedAnnotations => {
console.log(updatedAnnotations);
});
instance.addEventListener("annotations.delete", deletedAnnotations => {
console.log(deletedAnnotations);
});