Skip to content

Commit 777f229

Browse files
834567: Sample on How to Add Rectangle Annotations Using Search Text Bounds
1 parent 9f34e68 commit 777f229

File tree

12 files changed

+106
-52
lines changed

12 files changed

+106
-52
lines changed
File renamed without changes.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<template>
2+
<div id="app">
3+
<!-- Buttons for search controls -->
4+
<div style="margin-top: 20px;">
5+
<button @click="handleSearch">Search PDF</button>
6+
<button @click="handleSearchNext">Search Next</button>
7+
<button @click="handleCancelSearch">Cancel Search</button>
8+
</div>
9+
<!-- PDF Viewer Component -->
10+
<ejs-pdfviewer
11+
id="pdfViewer"
12+
ref="pdfviewer"
13+
:documentPath="documentPath"
14+
:resourceUrl="resourceUrl"
15+
@textSearchHighlight="handleTextSearchHighlight"
16+
>
17+
</ejs-pdfviewer>
18+
</div>
19+
</template>
20+
21+
<script>
22+
import {
23+
PdfViewerComponent,
24+
Toolbar,
25+
Magnification,
26+
Navigation,
27+
LinkAnnotation,
28+
BookmarkView,
29+
Annotation,
30+
ThumbnailView,
31+
Print,
32+
TextSelection,
33+
TextSearch,
34+
FormFields,
35+
FormDesigner,
36+
PageOrganizer,
37+
} from '@syncfusion/ej2-vue-pdfviewer';
38+
39+
export default {
40+
name: 'App',
41+
components: {
42+
'ejs-pdfviewer': PdfViewerComponent,
43+
},
44+
data() {
45+
return {
46+
resourceUrl: 'https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib',
47+
documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
48+
};
49+
},
50+
provide: {
51+
// Inject necessary modules
52+
PdfViewer: [
53+
Toolbar,
54+
Magnification,
55+
Navigation,
56+
LinkAnnotation,
57+
BookmarkView,
58+
Annotation,
59+
ThumbnailView,
60+
Print,
61+
TextSelection,
62+
TextSearch,
63+
FormFields,
64+
FormDesigner,
65+
PageOrganizer,
66+
],
67+
},
68+
methods: {
69+
// Method to initiate a text search for the term 'PDF'
70+
handleSearch() {
71+
this.$refs.pdfviewer.ej2Instances.textSearchModule.searchText('PDF', false);
72+
},
73+
// Method to go to the next instance of the search term
74+
handleSearchNext() {
75+
this.$refs.pdfviewer.ej2Instances.textSearchModule.searchNext();
76+
},
77+
// Method to cancel the current text search operation
78+
handleCancelSearch() {
79+
this.$refs.pdfviewer.ej2Instances.textSearchModule.cancelTextSearch();
80+
},
81+
// Method to handle the text search highlight event
82+
handleTextSearchHighlight(args) {
83+
console.log(args); // Log for debugging
84+
const bounds=args.bounds;
85+
// Add a rectangle annotation on the highlighted text
86+
this.$refs.pdfviewer.ej2Instances.annotationModule.addAnnotation('Rectangle', {
87+
pageNumber: args.pageNumber,
88+
offset: { x: bounds.left, y: bounds.top },
89+
width: bounds.width,
90+
height: bounds.height,
91+
});
92+
},
93+
},
94+
};
95+
</script>
96+
97+
<style>
98+
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
99+
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
100+
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
101+
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
102+
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
103+
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
104+
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
105+
@import "../node_modules/@syncfusion/ej2-vue-pdfviewer/styles/material.css";
106+
</style>

0 commit comments

Comments
 (0)