Skip to content

Commit 323a0b6

Browse files
authored
Merge pull request #37 from SyncfusionExamples/EJ2-834567-getCoordinates
834567: How to Add Rectangle Annotations Using Search Text Bounds
2 parents 31e68f8 + bd1587e commit 323a0b6

20 files changed

+381
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.34607.79
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddRectangleUsingTextSearch", "AddRectangleUsingTextSearch\AddRectangleUsingTextSearch.csproj", "{9E1F3D8A-48BD-40BA-89B8-1A9D66BB82C3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9E1F3D8A-48BD-40BA-89B8-1A9D66BB82C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9E1F3D8A-48BD-40BA-89B8-1A9D66BB82C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9E1F3D8A-48BD-40BA-89B8-1A9D66BB82C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9E1F3D8A-48BD-40BA-89B8-1A9D66BB82C3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="*" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
7+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
8+
</PropertyGroup>
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace PDFViewerSample.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
28+
}
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace PDFViewerSample.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace PDFViewerSample.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
20+
}

0 commit comments

Comments
 (0)