# How to add/update/delete annotations based on condition?

**URL:** <https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950>\
**Category:** Technical Support\
**Created:** [August 15, 2022, 6:11am UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950 "2022-08-15T06:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arman](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@arman](https://pdfjs.community/u/arman)\
**Post date:** [August 15, 2022, 6:11am UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950/1 "2022-08-15T06:11:45Z")

</div>

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

**PDF.js Express Version**  
8.0.1

**Detailed description of issue**  
When the event “annotationChanged” will call, I want to add/update/delete annotations based on conditions otherwise not. But now it always add/update/delete annotations even after I added my conditions.

**Expected behaviour**  
After checking my condition. No annotation should be added/updated/deleted.

**Does your issue happen with every document, or just one?**  
Issue happens with every document

**Code snippet**

```javascript
annotationManager.addEventListener('annotationChanged', (annotations, action, { imported }) => {
      if (imported) {
        return;
      } else if(myCondition){
        // do something and return.
        return;
      } else {
        if (action === 'add') {
        console.log('this is a change that added annotations');
      } else if (action === 'modify') {
        console.log('this change modified annotations');
      } else if (action === 'delete') {
        console.log('there were annotations deleted');
      }
      }
    });

```

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [August 15, 2022, 6:11am UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950/3 "2022-08-15T06:11:50Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Real-time collaboration client](https://pdfjs.express/documentation/collaboration/realtime-collaboration-client.8)
- [Add annotation events - annotationChanged (add/modify/delete)](https://pdfjs.express/documentation/annotation/annotation-events.8#annotationchanged-(add/modify/delete))
- [Create fillable forms - Modify fields to readonly](https://pdfjs.express/documentation/forms/fill-form-fields.8#modify-fields-to-readonly)

APIs:
- [Core.AnnotationManager - deleteAnnotations(annotation [, options])](https://pdfjs.express/api/Core.AnnotationManager.html#deleteAnnotations__anchor)
- [UndefinedannotationChanged](https://pdfjs.express/api/namespaces.list.html#event:annotationChanged__anchor)
- [Core.Annotations.TextSquigglyAnnotation - new TextSquigglyAnnotation( [initializer])](https://pdfjs.express/api/Core.Annotations.TextSquigglyAnnotation.html#TextSquigglyAnnotation__anchor)

Forums:
- [Flipped annotations aren’t triggering annotationChanged (modify) event, also NOT getting saved/export](https://pdfjs.community/t/flipped-annotations-arent-triggering-annotationchanged-modify-event-also-not-getting-saved-export/591/1)
- [Annotations are getting displaced when zoom in and out are done abit fast](https://pdfjs.community/t/annotations-are-getting-displaced-when-zoom-in-and-out-are-done-abit-fast/567/1)
- [Annotations State or Status](https://pdfjs.community/t/annotations-state-or-status/1362/4)

---

<div class="post-metadata">

**Author:** ![zserviss](https://avatars.discourse-cdn.com/v4/letter/z/a9a28c/32.png) [@zserviss](https://pdfjs.community/u/zserviss)\
**Post date:** [August 15, 2022, 4:45pm UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950/4 "2022-08-15T16:45:54Z")

</div>

Hi Arman,

Because the event listener is just listening to events, trying to return from this method will not have an effect on the actual actions.

If you want to disable these actions, I would recommend enabling the read only mode.

> **[Set Annotation Permissions with PDF.js Express | Documentation](https://pdfjs.express/documentation/annotation/annotation-permissions#readonly-mode)**

Best Regards,  
Zach Serviss  
Web Development Support Engineer  
PDFTron Systems, Inc.
