# How to do two annotation Groupby programatically?

**URL:** <https://pdfjs.community/t/how-to-do-two-annotation-groupby-programatically/3079>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [January 16, 2024, 2:04pm UTC](https://pdfjs.community/t/how-to-do-two-annotation-groupby-programatically/3079 "2024-01-16T14:04:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahid.shaikh](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@shahid.shaikh](https://pdfjs.community/u/shahid.shaikh)\
**Post date:** [January 16, 2024, 2:04pm UTC](https://pdfjs.community/t/how-to-do-two-annotation-groupby-programatically/3079/1 "2024-01-16T14:04:08Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
8.7.4

**Detailed description of issue**  
I am adding two annotations RectangleAnnotation and FreeTextAnnotation annotation programmatically using the same coordinates I want to do groupby that both annotation programmatically how can i do it ? Please share reference or code to do it .

![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/9/99c32e40206ccc379a00ff67dbfcccd7c2dd3573.png)  
I am showing annotation like above snapshot want to do group by programmatically ?

---

<div class="post-metadata">

**Author:** ![ejohnson](https://avatars.discourse-cdn.com/v4/letter/e/a3d4f5/32.png) [@ejohnson](https://pdfjs.community/u/ejohnson)\
**Post date:** [January 16, 2024, 2:21pm UTC](https://pdfjs.community/t/how-to-do-two-annotation-groupby-programatically/3079/2 "2024-01-16T14:21:03Z")

</div>

Thank you for posting your question to our forum. We will provide you with an update as soon as possible.

---

<div class="post-metadata">

**Author:** ![darian.chen](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@darian.chen](https://pdfjs.community/u/darian.chen)\
**Post date:** [January 16, 2024, 5:09pm UTC](https://pdfjs.community/t/how-to-do-two-annotation-groupby-programatically/3079/3 "2024-01-16T17:09:16Z")

</div>

Hello Shahid,

After creating the two annotations you can use the groupAnnotations API to group them.  
[https://pdfjs.express/api/Core.AnnotationManager.html#groupAnnotations\_\_anchor](https://pdfjs.express/api/Core.AnnotationManager.html#groupAnnotations__anchor)

```javascript

    annotationManager.addAnnotation(rectangleAnnot);
    annotationManager.addAnnotation(freeTextAnnot);
    annotationManager.drawAnnotationsFromList([rectangleAnnot, freeTextAnnot]);

    // Group the annotations together
    annotationManager.groupAnnotations(rectangleAnnot, [freeTextAnnot]);

```

Best Regards,  
Darian
