Skip to content

Commit

Permalink
834567: How toAdd Rectangle Annotations Using Search Text Bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
SF4524LogeshKumar committed Dec 16, 2024
1 parent cd74989 commit 3479f3c
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@using Syncfusion.EJ2
@{
ViewBag.Title = "Home Page";
}
<!-- Control buttons for PDF Search functionality -->
<div style="margin-top: 20px;">
<button onclick="handleSearch()">Search PDF</button>
<button onclick="handleSearchNext()">Search Next</button>
<button onclick="handleCancelSearch()">Cancel Search</button>
</div>
<div>
<!-- Render PDF Viewer using the Html helper method -->
@Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf").TextSearchHighlight("handleTextSearchHighlight").Render()
</div>


<script type="text/javascript">
window.onload = function () {
// Access the PDF Viewer instance on page load
var pdfViewer = getPdfViewerInstance();
pdfViewer.enableLocalStorage = true; // Enable or configure as needed
};
// Function to get the PDF Viewer instance conveniently
function getPdfViewerInstance() {
return document.getElementById('pdfviewer').ej2_instances[0];
}
// Initiate search for the term 'PDF' in the document
function handleSearch() {
const pdfViewer = getPdfViewerInstance();
pdfViewer.textSearchModule.searchText('PDF', false);
}
// Move to next search result
function handleSearchNext() {
const pdfViewer = getPdfViewerInstance();
pdfViewer.textSearchModule.searchNext();
}
// Cancel any ongoing text search operation
function handleCancelSearch() {
const pdfViewer = getPdfViewerInstance();
pdfViewer.textSearchModule.cancelTextSearch();
}
// Event handler for when text is highlighted during search
function handleTextSearchHighlight(args) {
const pdfViewer = getPdfViewerInstance();
console.log(args); // Display highlight event data
const bounds = args.bounds;
// Add rectangle annotation around highlighted text
pdfViewer.annotationModule.addAnnotation('Rectangle', {
pageNumber: args.pageNumber,
offset: { x: bounds.left, y: bounds.top },
width: bounds.width,
height: bounds.height,
strokeColor: "red", // Customize the stroke color if desired
borderWidth: 2
});
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.2.2/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js"></script>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/28.1.33/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<package id="Microsoft.Web.Infrastructure" version="2.0.1" targetFramework="net472" />
<package id="Modernizr" version="2.8.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
<package id="Syncfusion.EJ2.JavaScript" version="*" targetFramework="net472" />
<package id="Syncfusion.EJ2.MVC5" version="*" targetFramework="net472" />
<package id="Syncfusion.Licensing" version="*" targetFramework="net472" />
<package id="Syncfusion.EJ2.JavaScript" version="28.1.33" targetFramework="net472" />
<package id="Syncfusion.EJ2.MVC5" version="28.1.33" targetFramework="net472" />
<package id="Syncfusion.Licensing" version="28.1.33" targetFramework="net472" />
<package id="WebGrease" version="1.6.0" targetFramework="net472" />
</packages>

This file was deleted.

0 comments on commit 3479f3c

Please sign in to comment.