Skip to content

Commit a714b5e

Browse files
834573: Optimized code using getPageInfo
1 parent 939e653 commit a714b5e

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

How to/Library Bounds to Viewer Bounds/PDFViewerSample/PDFViewerSample/Pages/Index.cshtml

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
document.addEventListener('DOMContentLoaded', function () {
2020
var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
2121
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-
};
3122
3223
pdfViewer.exportSuccess = function (args) {
3324
console.log(args.exportData);
@@ -41,37 +32,34 @@
4132
var shapeAnnotationData = datas['pdfAnnotation'][0]['shapeAnnotation'];
4233
shapeAnnotationData.forEach(data => {
4334
if (data && data.rect && parseInt(data.rect.width)) {
44-
var pageHeight = pageSizes[parseInt(data.page)].Height;
45-
35+
let rect = null;
36+
const pageHeight = pdfViewer.getPageInfo(parseInt(data.page)).height;
4637
// Converting PDF Library values into PDF Viewer values.
47-
var rect = {
38+
rect = {
4839
x: (parseInt(data.rect.x) * 96) / 72,
49-
50-
// Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
51-
// The conversion factor of 72/96 is used to change pixel values to points
52-
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
40+
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
5341
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
5442
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
5543
};
56-
console.log(data.name, rect, "-------------------------");
57-
}
5844
59-
if ((data.type == 'Line' || data.type == 'Arrow') && data.start && data.end) {
60-
const [startX, startY] = data.start.split(',').map(Number);
61-
const [endX, endY] = data.end.split(',').map(Number);
45+
if ((data.type == 'Line' || data.type == 'Arrow') && data.start && data.end) {
46+
const [startX, startY] = data.start.split(',').map(Number);
47+
const [endX, endY] = data.end.split(',').map(Number);
6248
63-
const pageHeight = pageSizes[parseInt(data.page)].Height;
64-
const pdfStartX = (startX * 96) / 72;
65-
const pdfStartY = (parseInt(pageHeight) * 72 / 96 - startY) * 96 / 72;
66-
const pdfEndX = (endX * 96) / 72;
67-
const pdfEndY = (parseInt(pageHeight) * 72 / 96 - endY) * 96 / 72;
49+
const pageHeight = pdfViewer.getPageInfo(parseInt(data.page)).height;
50+
const pdfStartX = (startX * 96) / 72;
51+
const pdfStartY = (parseInt(pageHeight) - startY) * 96 / 72;
52+
const pdfEndX = (endX * 96) / 72;
53+
const pdfEndY = (parseInt(pageHeight) - endY) * 96 / 72;
6854
69-
var rect = {
70-
x: Math.min(pdfStartX, pdfEndX),
71-
y: Math.min(pdfStartY, pdfEndY),
72-
width: Math.abs(pdfEndX - pdfStartX),
73-
height: Math.abs(pdfEndY - pdfStartY),
74-
};
55+
rect = {
56+
x: Math.min(pdfStartX, pdfEndX),
57+
y: Math.min(pdfStartY, pdfEndY),
58+
width: Math.abs(pdfEndX - pdfStartX),
59+
height: Math.abs(pdfEndY - pdfStartY),
60+
};
61+
62+
}
7563
7664
console.log(data.name, rect, "-------------------------");
7765
}

How to/Library Bounds to Viewer Bounds/PDFViewerSample/PDFViewerSample/Pages/Shared/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
99
<link rel="stylesheet" href="~/PDFViewerSample.styles.css" asp-append-version="true" />
1010
<!-- Syncfusion ASP.NET Core controls styles -->
11-
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.48/fluent.css" />
11+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.57/fluent.css" />
1212
<!-- Syncfusion ASP.NET Core controls scripts -->
13-
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js"></script>
13+
<script src="https://cdn.syncfusion.com/ej2/27.1.57/dist/ej2.min.js"></script>
1414
</head>
1515
<body>
1616
<div class="container">

0 commit comments

Comments
 (0)