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, you can use Instance#delete. This API requires the annotation IDs only:

PSPDFKit.load(configuration).then(async (instance) => {
  const annotations = await instance.getAnnotations(0);
  const annotation = annotations.get(0);
  await instance.delete(annotation);

  console.log("Annotation deleted.");

Once annotations have been removed, they’ll need to be persisted. This is done by saving them. You can save them to external storage or embed them into the document. They can also be exported to XFDF or Instant JSON, or synced to the optional PSPDFKit Server.