How do I prevent printing Annotations?

Q: How do I prevent printing Annotations?

A: For some use-cases, you might want to print your document without annotations. This where the noPrint flag comes in handy. Let’s see how we can apply this to all annotations in the document:

(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.updateAnnotation(annotation.set('noPrint', true)) // do not print the annotation
        )
      )
    );
  })();