Skip to content

Commit 908fe1b

Browse files
834567: Sample on How to Add Rectangle Annotations Using Search Text Bounds
1 parent 5e2076f commit 908fe1b

File tree

20 files changed

+58
-21
lines changed

20 files changed

+58
-21
lines changed

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample.sln renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample.sln

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/PDFViewerSample.csproj renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/PDFViewerSample.csproj

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/PDFViewerSample.csproj.user renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/PDFViewerSample.csproj.user

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Error.cshtml renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Error.cshtml

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Error.cshtml.cs renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Error.cshtml.cs

File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@page "{handler?}"
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
<div class="text-center">
7+
<!-- Control buttons for PDF Search functionality -->
8+
<div style="margin-top: 20px;">
9+
<button onclick="handleSearch()">Search PDF</button>
10+
<button onclick="handleSearchNext()">Search Next</button>
11+
<button onclick="handleCancelSearch()">Cancel Search</button>
12+
</div>
13+
<ejs-pdfviewer id="pdfviewer" style="height:600px"
14+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
15+
resourceUrl="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib"
16+
textSearchHighlight="handleTextSearchHighlight">
17+
</ejs-pdfviewer>
18+
</div>
19+
<script type="text/javascript">
20+
21+
// Function to get the PDF Viewer instance
22+
function getPdfViewerInstance() {
23+
return document.getElementById('pdfviewer').ej2_instances[0];
24+
}
25+
26+
// Initiates a search for the term 'PDF' in the document
27+
function handleSearch() {
28+
const pdfViewer = getPdfViewerInstance();
29+
pdfViewer.textSearchModule.searchText('PDF', false);
30+
}
31+
32+
// Searches for the next occurrence of the term
33+
function handleSearchNext() {
34+
const pdfViewer = getPdfViewerInstance();
35+
pdfViewer.textSearchModule.searchNext();
36+
}
37+
38+
// Cancels the current text search operation
39+
function handleCancelSearch() {
40+
const pdfViewer = getPdfViewerInstance();
41+
pdfViewer.textSearchModule.cancelTextSearch();
42+
}
43+
44+
45+
// Event handler for annotation addition
46+
// Adds a rectangle annotation around highlighted text
47+
function handleTextSearchHighlight(args) {
48+
console.log(args); // Log details of the added annotation around highlighted text
49+
const pdfViewer = getPdfViewerInstance();
50+
const bounds = args.bounds;
51+
pdfViewer.annotationModule.addAnnotation('Rectangle', {
52+
pageNumber: args.pageNumber,
53+
offset: { x: bounds.left, y: bounds.top },
54+
width: bounds.width,
55+
height: bounds.height,
56+
});
57+
}
58+
</script>

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Index.cshtml.cs renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Index.cshtml.cs

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Privacy.cshtml renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Privacy.cshtml

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Privacy.cshtml.cs renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Privacy.cshtml.cs

File renamed without changes.

How to/Get co-ordinates of Annotations/PDFViewerSample/PDFViewerSample/Pages/Shared/_Layout.cshtml renamed to How to/Add Rectangle Annotations Using Search Text Bounds/PDFViewerSample/PDFViewerSample/Pages/Shared/_Layout.cshtml

File renamed without changes.

0 commit comments

Comments
 (0)