Skip to content

Commit

Permalink
834567: Sample on How to Add Rectangle Annotations Using Search Text …
Browse files Browse the repository at this point in the history
…Bounds
  • Loading branch information
SF4524LogeshKumar committed Dec 16, 2024
1 parent fe6b6fc commit 26d822f
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { pdf } from '@syncfusion/ej2';
import { PdfViewer, TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields, TextSearchHighlightEventArgs, RectangleBounds, RectangleBoundsModel, RectangleSettings } from '@syncfusion/ej2-pdfviewer';

// Inject required modules
PdfViewer.Inject(TextSelection, TextSearch, Print, Navigation, Toolbar, Magnification, Annotation, FormDesigner, FormFields);

const pdfviewer: PdfViewer = new PdfViewer({
documentPath: 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf',
resourceUrl:'https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib'
});

pdfviewer.appendTo('#PdfViewer');

// Highlight event handler for text search, which adds a rectangle annotation where the text is found
pdfviewer.textSearchHighlight = function(args: TextSearchHighlightEventArgs): void {
console.log(args);
const pageNumber: number = args.pageNumber;
const bounds: RectangleBoundsModel = args.bounds;
pdfviewer.annotation.addAnnotation('Rectangle', {
offset: { x: bounds.left, y: bounds.top },
pageNumber: pageNumber,
width: bounds.width,
height: bounds.height,
} as RectangleSettings);
};

// Add event listener to "searchText" button to trigger a search for the term 'PDF'
const searchTextButton = document.getElementById('searchText');
if (searchTextButton) {
searchTextButton.addEventListener('click', function() {
pdfviewer.textSearchModule.searchText('PDF', false);
});
}

// Add event listener to "searchNext" button to navigate to the next search result
const searchNextButton = document.getElementById('searchNext');
if (searchNextButton) {
searchNextButton.addEventListener('click', function() {
pdfviewer.textSearch.searchNext();
});
}

// Add event listener to "searchCancel" button to cancel the current text search operation
const searchCancelButton = document.getElementById('searchCancel');
if (searchCancelButton) {
searchCancelButton.addEventListener('click', function() {
pdfviewer.textSearch.cancelTextSearch();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</head>

<body>
<button id="searchText">Search Text</button>
<button id="searchNext">Search Next</button>
<button id="searchCancel">Cancel Search</button>
<!--Element which will render as PDF Viewer -->
<div id="PdfViewer"></div>
</body>
Expand Down
17 changes: 0 additions & 17 deletions How to/Get co-ordinates of Annotations/src/app/app.ts

This file was deleted.

0 comments on commit 26d822f

Please sign in to comment.