Clear annotations in React PDF Viewer
14 Jul 20261 minute to read
Use the deleteAnnotations method to clear all annotations in the currently loaded document.
Example: Clear all annotations in the loaded document
<button onclick="deleteAnnotations()">Delete Annotations</button>
<script>
// Clear all annotations
function deleteAnnotations() {
var viewer = document.getElementById("container").ej2_instances[0];
viewer.deleteAnnotations();
}
</script>To remove a specific annotation, use the deleteAnnotationById method to target an annotation by its id.
Example: Delete a specific annotation by ID
<button onclick="deleteAnnotationById()">Delete Annotation by ID</button>
<script>
// Delete an annotation by id
function deleteAnnotationById() {
var viewer = document.getElementById("container").ej2_instances[0];
if (viewer.annotationCollection && viewer.annotationCollection.length > 0) {
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}
}
</script>