Is there an API method that counts the number of comment annotations on a PDF? How would one go about getting this value?

PDF.js Express Version 7.2

Detailed description of issue
I’m trying to find the best way to count the number of individual comments on a PDF. I haven’t been able to find a method in the API so far.

Hey there!

You can use the getAnnotationsList api to get an array of all the annotations, and then loop over it to count the annots that you’re interested in.

  instance.docViewer.on('annotationsLoaded', () => {
    const annots = instance.annotManager.getAnnotationsList()
    const count = annots.reduce((acc, annot) => { 
      if (annot instanceof instance.Annotations.StickyAnnotation) {
        return acc + 1;
      }

      return acc;
    }, 0)
  })

Let me know if you have any other questions.

Thanks!
Logan

Thanks! We have one main question for our implementation. I’ll create a new topic for it.