Delete annotation in Vue PDF Viewer control
28 Feb 20266 minutes to read
This article shows how to remove a specific annotation from a PDF document using the deleteAnnotationById() method. The example below demonstrates a simple delete flow.
The following steps are used to delete a specific annotation from PDF Document:
Step 1: Create a basic PDF Viewer sample by following the getting-started guide.
Step 2: Use the following snippet to trigger deletion using deleteAnnotationById().
<template>
<div id="app">
<button v-on:click="deleteAnnotationById">Delete Annotation By Id</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
// Delete annotation by ID.
const deleteAnnotationById = function () {
const viewer = pdfviewer.value.ej2Instances;
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}
</script><template>
<div id="app">
<button v-on:click="deleteAnnotationById">Delete Annotation By Id</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
// Delete annotation by ID.
deleteAnnotationById: function () {
const viewer = this.$refs.pdfviewer.ej2Instances;
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}
}
}
</script><template>
<div id="app">
<button v-on:click="deleteAnnotationById">Delete Annotation By Id</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :serviceUrl="serviceUrl" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const serviceUrl = "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer";
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
// Delete annotation by ID.
const deleteAnnotationById = function () {
const viewer = pdfviewer.ej2Instances;
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}
</script><template>
<div id="app">
<button v-on:click="deleteAnnotationById">Delete Annotation By Id</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :serviceUrl="serviceUrl" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
// Delete annotation by ID.
deleteAnnotationById: function () {
const viewer = this.$refs.pdfviewer.ej2Instances;
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}
}
}
</script>Note :
If you use the deleteAnnotation API to delete an annotation, select an annotation first using the selectAnnotation API. You can’t delete an annotation without selecting that annotation.
Find the sample, how to delete a specific annotation using deleteAnnotationById