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

**URL:** <https://pdfjs.community/t/is-there-an-api-method-that-counts-the-number-of-comment-annotations-on-a-pdf-how-would-one-go-about-getting-this-value/538>\
**Category:** Technical Support\
**Created:** [February 25, 2021, 12:16am UTC](https://pdfjs.community/t/is-there-an-api-method-that-counts-the-number-of-comment-annotations-on-a-pdf-how-would-one-go-about-getting-this-value/538 "2021-02-25T00:16:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [February 25, 2021, 12:16am UTC](https://pdfjs.community/t/is-there-an-api-method-that-counts-the-number-of-comment-annotations-on-a-pdf-how-would-one-go-about-getting-this-value/538/1 "2021-02-25T00:16:56Z")

</div>

**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.

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 1, 2021, 5:30pm UTC](https://pdfjs.community/t/is-there-an-api-method-that-counts-the-number-of-comment-annotations-on-a-pdf-how-would-one-go-about-getting-this-value/538/2 "2021-03-01T17:30:34Z")

</div>

Hey there!

You can use the [`getAnnotationsList`](https://pdfjs.express/api/CoreControls.AnnotationManager.html#getAnnotationsList__anchor) api to get an array of all the annotations, and then loop over it to count the annots that you’re interested in.

```javascript
  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

---

<div class="post-metadata">

**Author:** ![psilva](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@psilva](https://pdfjs.community/u/psilva)\
**Post date:** [March 1, 2021, 6:24pm UTC](https://pdfjs.community/t/is-there-an-api-method-that-counts-the-number-of-comment-annotations-on-a-pdf-how-would-one-go-about-getting-this-value/538/3 "2021-03-01T18:24:59Z")

</div>

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