Skip to content

Commit

Permalink
834573: optimized code using getPageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
SF4524LogeshKumar committed Nov 7, 2024
1 parent 4c978da commit 8ac57e4
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions How to/Library Bounds to Viewer Bounds/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
:documentPath="documentPath"
:serviceUrl="serviceUrl"
style="height: 640px;"
@ajaxRequestSuccess="handleAjaxRequestSuccess"
@exportSuccess="handleExportSuccess"
>
</ejs-pdfviewer>
Expand All @@ -26,22 +25,12 @@ export default {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
serviceUrl: "https://services.syncfusion.com/js/production/api/pdfviewer",
pageSizes: []
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, Annotation, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer]
},
methods: {
handleAjaxRequestSuccess(args) {
if (args.action === 'Load') {
const objLength = Object.keys(args.data.pageSizes).length;
for (let x = 0; x < objLength; x++) {
const pageSize = args.data.pageSizes[x];
this.pageSizes.push(pageSize);
}
}
},
handleExportSuccess(args) {
const blobURL = args.exportData;
// Converting the exported blob into an object
Expand All @@ -51,19 +40,14 @@ export default {
const shapeAnnotationData = objectData.pdfAnnotation[0].shapeAnnotation;
shapeAnnotationData.forEach(data => {
if (data && data.rect && parseInt(data.rect.width)) {
const pageHeight = this.pageSizes[parseInt(data.page)].Height;
const pageHeight = this.$refs.pdfviewer.getPageInfo(parseInt(data.page)).height;
// Converting PDF Library values into PDF Viewer values.
const rect = {
x: (parseInt(data.rect.x) * 96) / 72,
// Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
// The conversion factor of 72/96 is used to change pixel values to points
y: (parseInt(pageHeight) * 72 / 96 - parseInt(data.rect.height)) * 96 / 72,
y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72,
width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72,
height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72,
};
console.log(data.name);
console.log(rect);
console.log("-------------------------");
Expand All @@ -74,6 +58,7 @@ export default {
console.error('Error converting Blob URL to object:', error);
});
},
//Function to convert Blob URL to object
convertBlobURLToObject(blobURL) {
return fetch(blobURL)
.then((response) => response.blob())
Expand Down

0 comments on commit 8ac57e4

Please sign in to comment.