Skip to content

Commit a3137fd

Browse files
834573: optimized code
1 parent e77b06e commit a3137fd

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

How to/Library Bounds to Viewer bounds/index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
<meta name="description" content="Typescript PDF Viewer Control">
66
<meta name="author" content="Syncfusion">
77
<!-- <link href="index.css" rel="stylesheet"> -->
8-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-base/styles/material.css" rel="stylesheet">
9-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-pdfviewer/styles/material.css" rel="stylesheet">
10-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-buttons/styles/material.css" rel="stylesheet">
11-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-popups/styles/material.css" rel="stylesheet">
12-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-navigations/styles/material.css" rel="stylesheet">
13-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-dropdowns/styles/material.css" rel="stylesheet">
14-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-lists/styles/material.css" rel="stylesheet">
15-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-inputs/styles/material.css" rel="stylesheet">
16-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-splitbuttons/styles/material.css" rel="stylesheet">
17-
<link href="https://cdn.syncfusion.com/ej2/27.1.48/ej2-notifications/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-base/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-pdfviewer/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-buttons/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-popups/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-navigations/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-dropdowns/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-lists/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-inputs/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-splitbuttons/styles/material.css" rel="stylesheet">
17+
<link href="https://cdn.syncfusion.com/ej2/27.1.57/ej2-notifications/styles/material.css" rel="stylesheet">
1818

1919
<!-- Essential JS 2 PDF Viewer's script -->
20-
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/27.1.57/dist/ej2.min.js" type="text/javascript"></script>
2121
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
2222

2323
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>

How to/Library Bounds to Viewer bounds/index.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@ var pdfviewer = new ej.pdfviewer.PdfViewer({
33
serviceUrl: 'https://services.syncfusion.com/js/production/api/pdfviewer'
44
});
55
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.Toolbar,
6-
ej.pdfviewer.Magnification, ej.pdfviewer.Annotation, ej.pdfviewer.FormDesigner, ej.pdfviewer.FormFields, ej.pdfviewer.PageOrganizer);
7-
pdfviewer.appendTo('#PdfViewer');
8-
var pageSizes = [];
9-
pdfviewer.ajaxRequestSuccess = function (args) {
10-
if (args.action === 'Load') {
11-
let objLength = Object.keys(args.data.pageSizes).length;
12-
for (var x = 0; x < objLength; x++) {
13-
var pageSize = args.data.pageSizes[x];
14-
pageSizes.push(pageSize);
15-
}
16-
}
17-
};
18-
6+
ej.pdfviewer.Magnification, ej.pdfviewer.Annotation, ej.pdfviewer.FormDesigner, ej.pdfviewer.FormFields, ej.pdfviewer.PageOrganizer);
7+
pdfviewer.appendTo('#PdfViewer');
198

209
pdfviewer.exportSuccess = function (args) {
2110
console.log(args.exportData);
@@ -30,17 +19,12 @@ pdfviewer.exportSuccess = function (args) {
3019
shapeAnnotationData.map(data => {
3120
if (data && data.rect && parseInt(data.rect.width)) {
3221

33-
//var pageHeight=parseInt(data.rect.height);
34-
var pageHeight = pageSizes[parseInt(data.page)].Height
22+
var pageHeight = pdfviewer.getPageInfo(pdfviewer.currentPageNumber).height;
3523

3624
// Converting PDF Library values into PDF Viewer values.
3725
var rect = {
3826
x: (parseInt(data.rect.x) * 96) / 72,
39-
40-
// Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
41-
// The conversion factor of 72/96 is used to change pixel values to points
42-
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
43-
27+
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
4428
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
4529
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
4630
};
@@ -51,11 +35,11 @@ pdfviewer.exportSuccess = function (args) {
5135
const [endX, endY] = data.end.split(',').map(Number);
5236

5337
// Convert to PDF Viewer coordinates
54-
const pageHeight = pageSizes[parseInt(data.page)].Height;
38+
var pageHeight = pdfviewer.getPageInfo(pdfviewer.currentPageNumber).height;
5539
const pdfStartX = (startX * 96) / 72;
56-
const pdfStartY = (parseInt(pageHeight) * 72 / 96 - startY) * 96 / 72;
40+
const pdfStartY = (parseInt(pageHeight) - startY) * 96 / 72;
5741
const pdfEndX = (endX * 96) / 72;
58-
const pdfEndY = (parseInt(pageHeight) * 72 / 96 - endY) * 96 / 72;
42+
const pdfEndY = (parseInt(pageHeight) - endY) * 96 / 72;
5943

6044
rect = {
6145
x: Math.min(pdfStartX, pdfEndX),
@@ -64,7 +48,8 @@ pdfviewer.exportSuccess = function (args) {
6448
height: Math.abs(pdfEndY - pdfStartY),
6549
};
6650
}
67-
if (rect != null && data.type!='Text') {
51+
52+
if (rect != null && data.type != 'Text') {
6853
console.log(data.name);
6954
console.log(rect);
7055
console.log("-------------------------");
@@ -76,6 +61,7 @@ pdfviewer.exportSuccess = function (args) {
7661
});
7762
};
7863

64+
// Function to convert Blob URL to object
7965
function convertBlobURLToObject(blobURL) {
8066
return fetch(blobURL)
8167
.then((response) => response.blob())

0 commit comments

Comments
 (0)