Skip to content

Commit 72d1d22

Browse files
authored
Merge pull request #33 from SyncfusionExamples/EJ2-834573-LibraryBounds
834573: Library Bounds to Viewer Bounds sample
2 parents e58386f + 64bccdf commit 72d1d22

19 files changed

+650
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="*" />
12+
</ItemGroup>
13+
14+
</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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
@page "{handler?}"
3+
@model IndexModel
4+
@{
5+
ViewData["Title"] = "Home page";
6+
}
7+
8+
<div class="text-center">
9+
<ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/Index" documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf">
10+
</ejs-pdfviewer>
11+
</div>
12+
13+
<script type="text/javascript">
14+
var pageSizes = [];
15+
16+
// Event when the PDF is loaded
17+
document.addEventListener('DOMContentLoaded', function () {
18+
var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
19+
20+
21+
pdfViewer.exportSuccess = function (args) {
22+
console.log(args.exportData);
23+
const blobURL = args.exportData;
24+
25+
// Converting the exported blob into object
26+
convertBlobURLToObject(blobURL)
27+
.then((objectData) => {
28+
console.log(objectData);
29+
var datas = objectData;
30+
var shapeAnnotationData = datas['pdfAnnotation'][0]['shapeAnnotation'];
31+
shapeAnnotationData.forEach(data => {
32+
if (data && data.rect && parseInt(data.rect.width)) {
33+
let rect = null;
34+
const pageHeight = pdfViewer.getPageInfo(parseInt(data.page)).height;
35+
// Converting PDF Library values into PDF Viewer values.
36+
rect = {
37+
x: (parseInt(data.rect.x) * 96) / 72,
38+
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
39+
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
40+
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
41+
};
42+
43+
if ((data.type == 'Line' || data.type == 'Arrow') && data.start && data.end) {
44+
const [startX, startY] = data.start.split(',').map(Number);
45+
const [endX, endY] = data.end.split(',').map(Number);
46+
47+
const pageHeight = pdfViewer.getPageInfo(parseInt(data.page)).height;
48+
const pdfStartX = (startX * 96) / 72;
49+
const pdfStartY = (parseInt(pageHeight) - startY) * 96 / 72;
50+
const pdfEndX = (endX * 96) / 72;
51+
const pdfEndY = (parseInt(pageHeight) - endY) * 96 / 72;
52+
53+
rect = {
54+
x: Math.min(pdfStartX, pdfEndX),
55+
y: Math.min(pdfStartY, pdfEndY),
56+
width: Math.abs(pdfEndX - pdfStartX),
57+
height: Math.abs(pdfEndY - pdfStartY),
58+
};
59+
60+
}
61+
62+
console.log(data.name, rect, "-------------------------");
63+
}
64+
});
65+
})
66+
.catch((error) => {
67+
console.error('Error converting Blob URL to object:', error);
68+
});
69+
};
70+
71+
function convertBlobURLToObject(blobURL) {
72+
return fetch(blobURL)
73+
.then((response) => response.blob())
74+
.then((blobData) => {
75+
return new Promise((resolve, reject) => {
76+
const reader = new FileReader();
77+
reader.onloadend = () => {
78+
resolve(JSON.parse(reader.result));
79+
};
80+
reader.onerror = reject;
81+
reader.readAsText(blobData);
82+
});
83+
});
84+
}
85+
});
86+
</script>

0 commit comments

Comments
 (0)