Skip to content

Commit 8ac57e4

Browse files
834573: optimized code using getPageInfo
1 parent 4c978da commit 8ac57e4

File tree

1 file changed

+3
-18
lines changed
  • How to/Library Bounds to Viewer Bounds/src

1 file changed

+3
-18
lines changed

How to/Library Bounds to Viewer Bounds/src/App.vue

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
:documentPath="documentPath"
77
:serviceUrl="serviceUrl"
88
style="height: 640px;"
9-
@ajaxRequestSuccess="handleAjaxRequestSuccess"
109
@exportSuccess="handleExportSuccess"
1110
>
1211
</ejs-pdfviewer>
@@ -26,22 +25,12 @@ export default {
2625
return {
2726
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
2827
serviceUrl: "https://services.syncfusion.com/js/production/api/pdfviewer",
29-
pageSizes: []
3028
};
3129
},
3230
provide: {
3331
PdfViewer: [Toolbar, Magnification, Navigation, Annotation, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer]
3432
},
3533
methods: {
36-
handleAjaxRequestSuccess(args) {
37-
if (args.action === 'Load') {
38-
const objLength = Object.keys(args.data.pageSizes).length;
39-
for (let x = 0; x < objLength; x++) {
40-
const pageSize = args.data.pageSizes[x];
41-
this.pageSizes.push(pageSize);
42-
}
43-
}
44-
},
4534
handleExportSuccess(args) {
4635
const blobURL = args.exportData;
4736
// Converting the exported blob into an object
@@ -51,19 +40,14 @@ export default {
5140
const shapeAnnotationData = objectData.pdfAnnotation[0].shapeAnnotation;
5241
shapeAnnotationData.forEach(data => {
5342
if (data && data.rect && parseInt(data.rect.width)) {
54-
const pageHeight = this.pageSizes[parseInt(data.page)].Height;
55-
43+
const pageHeight = this.$refs.pdfviewer.getPageInfo(parseInt(data.page)).height;
5644
// Converting PDF Library values into PDF Viewer values.
5745
const rect = {
5846
x: (parseInt(data.rect.x) * 96) / 72,
59-
60-
// Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
61-
// The conversion factor of 72/96 is used to change pixel values to points
62-
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
47+
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
6348
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
6449
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
6550
};
66-
6751
console.log(data.name);
6852
console.log(rect);
6953
console.log("-------------------------");
@@ -74,6 +58,7 @@ export default {
7458
console.error('Error converting Blob URL to object:', error);
7559
});
7660
},
61+
//Function to convert Blob URL to object
7762
convertBlobURLToObject(blobURL) {
7863
return fetch(blobURL)
7964
.then((response) => response.blob())

0 commit comments

Comments
 (0)