|
| 1 | +<template> |
| 2 | + <div id="app"> |
| 3 | + <ejs-pdfviewer |
| 4 | + id="pdfViewer" |
| 5 | + ref="pdfviewer" |
| 6 | + :documentPath="documentPath" |
| 7 | + :serviceUrl="serviceUrl" |
| 8 | + style="height: 640px;" |
| 9 | + @exportSuccess="handleExportSuccess" |
| 10 | + > |
| 11 | + </ejs-pdfviewer> |
| 12 | + </div> |
| 13 | +</template> |
| 14 | + |
| 15 | +<script> |
| 16 | +import { PdfViewerComponent, Toolbar, Magnification, Navigation, |
| 17 | + Annotation, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer } from '@syncfusion/ej2-vue-pdfviewer'; |
| 18 | +
|
| 19 | +export default { |
| 20 | + name: 'App', |
| 21 | + components: { |
| 22 | + 'ejs-pdfviewer': PdfViewerComponent |
| 23 | + }, |
| 24 | + data() { |
| 25 | + return { |
| 26 | + documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf", |
| 27 | + serviceUrl: "https://services.syncfusion.com/js/production/api/pdfviewer", |
| 28 | + }; |
| 29 | + }, |
| 30 | + provide: { |
| 31 | + PdfViewer: [Toolbar, Magnification, Navigation, Annotation, TextSelection, TextSearch, FormFields, FormDesigner, PageOrganizer] |
| 32 | + }, |
| 33 | + methods: { |
| 34 | + handleExportSuccess(args) { |
| 35 | + const blobURL = args.exportData; |
| 36 | + // Converting the exported blob into an object |
| 37 | + this.convertBlobURLToObject(blobURL) |
| 38 | + .then((objectData) => { |
| 39 | + console.log(objectData); |
| 40 | + const shapeAnnotationData = objectData.pdfAnnotation[0].shapeAnnotation; |
| 41 | + shapeAnnotationData.forEach(data => { |
| 42 | + if (data && data.rect && parseInt(data.rect.width)) { |
| 43 | + const pageHeight = this.$refs.pdfviewer.getPageInfo(parseInt(data.page)).height; |
| 44 | + // Converting PDF Library values into PDF Viewer values. |
| 45 | + const rect = { |
| 46 | + x: (parseInt(data.rect.x) * 96) / 72, |
| 47 | + y: (parseInt(pageHeight) - parseInt(data.rect.height)) * 96 / 72, |
| 48 | + width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72, |
| 49 | + height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72, |
| 50 | + }; |
| 51 | + console.log(data.name); |
| 52 | + console.log(rect); |
| 53 | + console.log("-------------------------"); |
| 54 | + } |
| 55 | + }); |
| 56 | + }) |
| 57 | + .catch((error) => { |
| 58 | + console.error('Error converting Blob URL to object:', error); |
| 59 | + }); |
| 60 | + }, |
| 61 | + //Function to convert Blob URL to object |
| 62 | + convertBlobURLToObject(blobURL) { |
| 63 | + return fetch(blobURL) |
| 64 | + .then((response) => response.blob()) |
| 65 | + .then((blobData) => { |
| 66 | + return new Promise((resolve, reject) => { |
| 67 | + const reader = new FileReader(); |
| 68 | + reader.onloadend = () => { |
| 69 | + resolve(JSON.parse(reader.result)); |
| 70 | + }; |
| 71 | + reader.onerror = reject; |
| 72 | + reader.readAsText(blobData); |
| 73 | + }); |
| 74 | + }); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +</script> |
| 79 | + |
| 80 | +<style> |
| 81 | +@import "../node_modules/@syncfusion/ej2-base/styles/material.css"; |
| 82 | +@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css"; |
| 83 | +@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css"; |
| 84 | +@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css"; |
| 85 | +@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css"; |
| 86 | +@import "../node_modules/@syncfusion/ej2-popups/styles/material.css"; |
| 87 | +@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css"; |
| 88 | +@import "../node_modules/@syncfusion/ej2-vue-pdfviewer/styles/material.css"; |
| 89 | +</style> |
0 commit comments