Delete all annotations

Q: We want to delete all annotations in the document at once.

A: There’s no specific command to delete all annotations. However, it can be easily achieved by iterating the pages, retrieving all its annotations and calling PSPDFKit.Instance#delete() on their IDs:

PSPDFKit.load(configuration).then(instance => {
  (async () => {
    const pagesAnnotations = await Promise.all(
      Array.from({ length: instance.totalPageCount }).map((_, pageIndex) =>
        instance.getAnnotations(pageIndex)
      )
    );
    const annotationIds = pagesAnnotations.flatMap(pageAnnotations =>
      pageAnnotations.map(annotation => annotation.id).toArray()
    );
    await instance.delete(annotationIds)
  })();
});

This has been tested with PSPDFKit for Web 2020.5.0