|
19 | 19 | document.addEventListener('DOMContentLoaded', function () { |
20 | 20 | var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0]; |
21 | 21 |
|
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 | | - }; |
31 | 22 |
|
32 | 23 | pdfViewer.exportSuccess = function (args) { |
33 | 24 | console.log(args.exportData); |
|
41 | 32 | var shapeAnnotationData = datas['pdfAnnotation'][0]['shapeAnnotation']; |
42 | 33 | shapeAnnotationData.forEach(data => { |
43 | 34 | 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; |
46 | 37 | // Converting PDF Library values into PDF Viewer values. |
47 | | - var rect = { |
| 38 | + rect = { |
48 | 39 | 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, |
53 | 41 | width: (parseInt(data.rect.width) - parseInt(data.rect.x)) * 96 / 72, |
54 | 42 | height: (parseInt(data.rect.height) - parseInt(data.rect.y)) * 96 / 72, |
55 | 43 | }; |
56 | | - console.log(data.name, rect, "-------------------------"); |
57 | | - } |
58 | 44 |
|
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); |
62 | 48 |
|
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; |
68 | 54 |
|
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 | + } |
75 | 63 |
|
76 | 64 | console.log(data.name, rect, "-------------------------"); |
77 | 65 | } |
|
0 commit comments