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, or multiple annotations. However, it can be easily achieved by iterating the pages, retrieving all its annotations an calling PSPDFKit.Instance.deleteAnnotation() on each of their ids:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
PSPDFKit.load(configuration).then(instance => {
  (async () => {
    const pagesAnnotations = await Promise.all(
      Array.from({ length: instance.totalPageCount }).map((_, pageIndex) =>
        instance.getAnnotations(pageIndex)
      )
    );
    await Promise.all(
      pagesAnnotations.flatMap(pageAnnotations =>
        pageAnnotations.map(annotation =>
          instance.deleteAnnotation(annotation.id)
        )
      )
    );
  })();
});

This has been tested with PSPDFKit for Web 2019.3.1