How Do I Prevent Printing Annotations?

For some use cases, you might want to print your document without annotations. This where the noPrint flag comes in handy. The following code shows how to apply it to all annotations in a document:

(async () => {
  const pagesAnnotations = await Promise.all(
      length: instance.totalPageCount
    }).map((_, pageIndex) => instance.getAnnotations(pageIndex))
  await Promise.all(
    pagesAnnotations.flatMap((pageAnnotations) =>
        (annotation) =>
          instance.update(annotation.set("noPrint", true)) // Do not print the annotation.