Clear annotations in TypeScript PDF Viewer

16 Feb 20261 minute to read

Use the deleteAnnotations method to remove all annotations from the currently loaded document.

Example: Clear all annotations in the loaded document


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

// Attach a click handler to clear annotations
document.getElementById('deleteAnnotations').addEventListener('click',()=> {
  viewer.deleteAnnotations();
});

To remove a specific annotation, use the deleteAnnotationById method and provide the target annotation’s id

Example: delete a specific annotation by id


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

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

Sample: How to clear annotations using deleteAnnotations
https://stackblitz.com/edit/typescript-86gwqu?file=index.ts