Clear annotation in EJ2 TypeScript Pdfviewer control

6 Jul 20241 minute to read

To clear all the annotations in a PDF document using the Syncfusion PDF Viewer, you can use the deleteAnnotations method. This method is used to clear all the annotations present in the currently loaded document.

Here is an example of how you can clear all the annotations present in the currently loaded document:


 <button id="deleteAnnotations">Delete Annotations</button>

//clear Annotations.
document.getElementById('deleteAnnotations').addEventListener('click',()=> {
  viewer.deleteAnnotations();
})

We can also delete specific annotations with the deleteAnnotationById() method. This method is used to delete a specific annotation using its id.

Here is an example of how you can delete specific annotations with the deleteAnnotationById method:


 <button id="deleteAnnotationbyId">Delete Annotation By Id</button>

//Delete Annotation by ID.
document.getElementById('deleteAnnotationbyId').addEventListener('click', () => {
    viewer.annotationModule.deleteAnnotationById(
      viewer.annotationCollection[0].annotationId
    );
});

Find the sample how to clear annotations using deleteAnnotations