Skip to content

Commit 26d822f

Browse files
834567: Sample on How to Add Rectangle Annotations Using Search Text Bounds
1 parent fe6b6fc commit 26d822f

File tree

14 files changed

+52
-17
lines changed

14 files changed

+52
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { pdf } from '@syncfusion/ej2';
2+
import { PdfViewer, TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields, TextSearchHighlightEventArgs, RectangleBounds, RectangleBoundsModel, RectangleSettings } from '@syncfusion/ej2-pdfviewer';
3+
4+
// Inject required modules
5+
PdfViewer.Inject(TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields);
6+
7+
const pdfviewer: PdfViewer = new PdfViewer({
8+
documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
9+
resourceUrl:'https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib'
10+
});
11+
12+
pdfviewer.appendTo('#PdfViewer');
13+
14+
// Highlight event handler for text search, which adds a rectangle annotation where the text is found
15+
pdfviewer.textSearchHighlight = function(args: TextSearchHighlightEventArgs): void {
16+
console.log(args);
17+
const pageNumber: number = args.pageNumber;
18+
const bounds: RectangleBoundsModel = args.bounds;
19+
pdfviewer.annotation.addAnnotation('Rectangle', {
20+
offset: { x: bounds.left, y: bounds.top },
21+
pageNumber: pageNumber,
22+
width: bounds.width,
23+
height: bounds.height,
24+
} as RectangleSettings);
25+
};
26+
27+
// Add event listener to "searchText" button to trigger a search for the term 'PDF'
28+
const searchTextButton = document.getElementById('searchText');
29+
if (searchTextButton) {
30+
searchTextButton.addEventListener('click', function() {
31+
pdfviewer.textSearchModule.searchText('PDF', false);
32+
});
33+
}
34+
35+
// Add event listener to "searchNext" button to navigate to the next search result
36+
const searchNextButton = document.getElementById('searchNext');
37+
if (searchNextButton) {
38+
searchNextButton.addEventListener('click', function() {
39+
pdfviewer.textSearch.searchNext();
40+
});
41+
}
42+
43+
// Add event listener to "searchCancel" button to cancel the current text search operation
44+
const searchCancelButton = document.getElementById('searchCancel');
45+
if (searchCancelButton) {
46+
searchCancelButton.addEventListener('click', function() {
47+
pdfviewer.textSearch.cancelTextSearch();
48+
});
49+
}

How to/Get co-ordinates of Annotations/src/index.html renamed to How to/Add Rectangle Annotations Using Search Text Bounds/src/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
</head>
1313

1414
<body>
15+
<button id="searchText">Search Text</button>
16+
<button id="searchNext">Search Next</button>
17+
<button id="searchCancel">Cancel Search</button>
1518
<!--Element which will render as PDF Viewer -->
1619
<div id="PdfViewer"></div>
1720
</body>

How to/Get co-ordinates of Annotations/src/app/app.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)