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:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
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