@@ -18,21 +18,9 @@ import {
18
18
class App extends React . Component {
19
19
constructor ( props ) {
20
20
super ( props ) ;
21
- this . pageSizes = [ ] ;
22
21
this . viewerRef = React . createRef ( ) ;
23
22
}
24
23
25
- // Event for AJAX request success
26
- handleAjaxRequestSuccess = ( args ) => {
27
- if ( args . action === 'Load' ) {
28
- const objLength = Object . keys ( args . data . pageSizes ) . length ;
29
- for ( let x = 0 ; x < objLength ; x ++ ) {
30
- const pageSize = args . data . pageSizes [ x ] ;
31
- this . pageSizes . push ( pageSize ) ;
32
- }
33
- }
34
- } ;
35
-
36
24
// Event for export success
37
25
handleExportSuccess = ( args ) => {
38
26
console . log ( args . exportData ) ;
@@ -43,38 +31,34 @@ class App extends React.Component {
43
31
. then ( ( objectData ) => {
44
32
console . log ( objectData ) ;
45
33
const shapeAnnotationData = objectData [ 'pdfAnnotation' ] [ 0 ] [ 'shapeAnnotation' ] ;
34
+ let rect = null ;
46
35
shapeAnnotationData . forEach ( ( data ) => {
47
36
if ( data && data . rect && parseInt ( data . rect . width ) ) {
48
- const pageHeight = this . pageSizes [ parseInt ( data . page ) ] . Height ;
49
-
37
+ const pageHeight = this . viewerRef . current . getPageInfo ( parseInt ( data . page ) ) . height ;
50
38
// Converting PDF Library values into PDF Viewer values.
51
- const rect = {
39
+ rect = {
52
40
x : ( parseInt ( data . rect . x ) * 96 ) / 72 ,
53
-
54
- // Converting pageHeight from pixels(PDF Viewer) to points(PDF Library) for accurate positioning
55
- // The conversion factor of 72/96 is used to change pixel values to points
56
- y : ( parseInt ( pageHeight ) * 72 / 96 - parseInt ( data . rect . height ) ) * 96 / 72 ,
41
+ y : ( parseInt ( pageHeight ) - parseInt ( data . rect . height ) ) * 96 / 72 ,
57
42
width : ( parseInt ( data . rect . width ) - parseInt ( data . rect . x ) ) * 96 / 72 ,
58
43
height : ( parseInt ( data . rect . height ) - parseInt ( data . rect . y ) ) * 96 / 72 ,
59
44
} ;
60
- console . log ( data . name , rect , '-------------------------' ) ;
61
- }
62
- if ( ( data . type === 'Line' || data . type === 'Arrow' ) && data . start && data . end ) {
63
- const [ startX , startY ] = data . start . split ( ',' ) . map ( Number ) ;
64
- 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 ) ;
65
48
66
- const pageHeight = this . pageSizes [ parseInt ( data . page ) ] . Height ;
67
- const pdfStartX = ( startX * 96 ) / 72 ;
68
- const pdfStartY = ( parseInt ( pageHeight ) * 72 / 96 - startY ) * 96 / 72 ;
69
- const pdfEndX = ( endX * 96 ) / 72 ;
70
- const pdfEndY = ( parseInt ( pageHeight ) * 72 / 96 - endY ) * 96 / 72 ;
49
+ const pageHeight = this . viewerRef . current . 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 ;
71
54
72
- const rect = {
73
- x : Math . min ( pdfStartX , pdfEndX ) ,
74
- y : Math . min ( pdfStartY , pdfEndY ) ,
75
- width : Math . abs ( pdfEndX - pdfStartX ) ,
76
- height : Math . abs ( pdfEndY - pdfStartY ) ,
77
- } ;
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
+ }
78
62
console . log ( data . name , rect , '-------------------------' ) ;
79
63
}
80
64
} ) ;
0 commit comments