Skip to content

Commit b28b59b

Browse files
834573: Library Bounds to Viewer Bounds sample
1 parent 6bd32d9 commit b28b59b

19 files changed

+414
-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}") = "PDFViewerSample", "PDFViewerSample\PDFViewerSample.csproj", "{3936B843-A035-424E-BA4B-990436AC60BD}"
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+
{3936B843-A035-424E-BA4B-990436AC60BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3936B843-A035-424E-BA4B-990436AC60BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3936B843-A035-424E-BA4B-990436AC60BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3936B843-A035-424E-BA4B-990436AC60BD}.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
Lines changed: 13 additions & 0 deletions
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>
Lines changed: 9 additions & 0 deletions
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>
Lines changed: 26 additions & 0 deletions
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>
Lines changed: 28 additions & 0 deletions
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+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
@page "{handler?}"
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<ejs-pdfviewer id="pdfviewer"
9+
style="height:600px"
10+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
11+
serviceUrl="https://services.syncfusion.com/js/production/api/pdfviewer">
12+
</ejs-pdfviewer>
13+
</div>
14+
15+
<script type="text/javascript">
16+
var pageSizes = [];
17+
18+
// Event when the PDF is loaded
19+
document.addEventListener('DOMContentLoaded', function () {
20+
var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
21+
22+
pdfViewer.ajaxRequestSuccess = function (args) {
23+
if (args.action === 'Load') {
24+
let objLength = Object.keys(args.data.pageSizes).length;
25+
for (var x = 0; x < objLength; x++) {
26+
var pageSize = args.data.pageSizes[x];
27+
pageSizes.push(pageSize);
28+
}
29+
}
30+
};
31+
32+
pdfViewer.exportSuccess = function (args) {
33+
console.log(args.exportData);
34+
const blobURL = args.exportData;
35+
36+
// Converting the exported blob into object
37+
convertBlobURLToObject(blobURL)
38+
.then((objectData) => {
39+
console.log(objectData);
40+
var datas = objectData;
41+
var shapeAnnotationData = datas['pdfAnnotation'][0]['shapeAnnotation'];
42+
shapeAnnotationData.forEach(data => {
43+
if (data && data.rect && parseInt(data.rect.width)) {
44+
var pageHeight = pageSizes[parseInt(data.page)].Height;
45+
46+
// Converting PDF Library values into PDF Viewer values.
47+
var rect = {
48+
x: (parseInt(data.rect.x) * 96) / 72,
49+
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
50+
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
51+
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
52+
};
53+
console.log(data.name, rect, "-------------------------");
54+
}
55+
56+
if ((data.type == 'Line' || data.type == 'Arrow') && data.start && data.end) {
57+
const [startX, startY] = data.start.split(',').map(Number);
58+
const [endX, endY] = data.end.split(',').map(Number);
59+
60+
const pageHeight = pageSizes[parseInt(data.page)].Height;
61+
const pdfStartX = (startX * 96) / 72;
62+
const pdfStartY = (parseInt(pageHeight) * 72 / 96 - startY) * 96 / 72;
63+
const pdfEndX = (endX * 96) / 72;
64+
const pdfEndY = (parseInt(pageHeight) * 72 / 96 - endY) * 96 / 72;
65+
66+
var rect = {
67+
x: Math.min(pdfStartX, pdfEndX),
68+
y: Math.min(pdfStartY, pdfEndY),
69+
width: Math.abs(pdfEndX - pdfStartX),
70+
height: Math.abs(pdfEndY - pdfStartY),
71+
};
72+
73+
console.log(data.name, rect, "-------------------------");
74+
}
75+
});
76+
})
77+
.catch((error) => {
78+
console.error('Error converting Blob URL to object:', error);
79+
});
80+
};
81+
82+
function convertBlobURLToObject(blobURL) {
83+
return fetch(blobURL)
84+
.then((response) => response.blob())
85+
.then((blobData) => {
86+
return new Promise((resolve, reject) => {
87+
const reader = new FileReader();
88+
reader.onloadend = () => {
89+
resolve(JSON.parse(reader.result));
90+
};
91+
reader.onerror = reject;
92+
reader.readAsText(blobData);
93+
});
94+
});
95+
}
96+
});
97+
</script>
Lines changed: 20 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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>
Lines changed: 20 additions & 0 deletions
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - PDFViewerSample</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/PDFViewerSample.styles.css" asp-append-version="true" />
10+
<!-- Syncfusion ASP.NET Core controls styles -->
11+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.48/fluent.css" />
12+
<!-- Syncfusion ASP.NET Core controls scripts -->
13+
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js"></script>
14+
</head>
15+
<body>
16+
<div class="container">
17+
<main role="main" class="pb-3">
18+
@RenderBody()
19+
</main>
20+
</div>
21+
22+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
23+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
24+
<script src="~/js/site.js" asp-append-version="true"></script>
25+
26+
@await RenderSectionAsync("Scripts", required: false)
27+
<!-- Syncfusion ASP.NET Core Script Manager -->
28+
<ejs-scripts></ejs-scripts>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)