Remove PDF annotations using JavaScript
In addition to an API for editing annotations, we also provide an API for removing those annotations directly on the client. Following the optimistic UI approach, the changes will be instantly visible in the UI, but they aren’t persisted until the annotations are saved.
To remove annotations, use Instance#delete. This API requires the annotation IDs only. Try this example in the Playground(opens in a new tab):
NutrientViewer.load(configuration) .then(async (instance) => { try { const annotations = await instance.getAnnotations(0); console.log(`Found ${annotations.size} annotations`);
if (annotations.size === 0) { console.warn("No annotations found on page 0"); return; }
const annotation = annotations.get(0); await instance.delete(annotation); console.log("Annotation deleted."); } catch (error) { console.error("Failed to delete annotation:", error.message); } }) .catch((error) => { console.error("Failed to load NutrientViewer:", error.message); });Once annotations have been edited, they’ll need to be persisted. This is done by saving them. Save them to external storage or embed them into the document. They can also be exported to XFDF or Instant JSON. If you’re using Web SDK with Document Engine, they can be synced with the backend.