1
- import React , { useState } from "react" ;
1
+ import React from "react" ;
2
2
import RSC from "react-scrollbars-custom" ;
3
3
import { Document , Page } from "react-pdf" ;
4
4
import {
@@ -28,7 +28,8 @@ function RenderPdf({
28
28
pdfRequest,
29
29
signerObjectId,
30
30
signedSigners,
31
- setPdfLoadFail,
31
+ pdfLoad,
32
+ setPdfLoad,
32
33
placeholder,
33
34
setSignerPos,
34
35
setXyPostion,
@@ -55,19 +56,19 @@ function RenderPdf({
55
56
handleTextSettingModal,
56
57
setTempSignerId,
57
58
uniqueId,
58
- setPdfRenderHeight,
59
59
pdfOriginalWH,
60
60
scale
61
61
} ) {
62
- const [ isLoadPdf , setIsLoadPdf ] = useState ( false ) ;
63
-
64
62
const isMobile = window . innerWidth < 767 ;
65
63
//check isGuestSigner is present in local if yes than handle login flow header in mobile view
66
64
const isGuestSigner = localStorage . getItem ( "isGuestSigner" ) ;
67
65
68
66
// handle signature block width and height according to screen
69
67
const posWidth = ( pos , signYourself ) => {
70
- const containerScale = containerWH . width / pdfOriginalWH . width ;
68
+ const getPdfPageWidth = pdfOriginalWH . find (
69
+ ( data ) => data . pageNumber === pageNumber
70
+ ) ;
71
+ const containerScale = containerWH . width / getPdfPageWidth . width || 1 ;
71
72
const defaultWidth = defaultWidthHeight ( pos . type ) . width ;
72
73
const posWidth = pos . Width ? pos . Width : defaultWidth ;
73
74
if ( signYourself ) {
@@ -93,7 +94,10 @@ function RenderPdf({
93
94
}
94
95
} ;
95
96
const posHeight = ( pos , signYourself ) => {
96
- const containerScale = containerWH . width / pdfOriginalWH . width ;
97
+ const getPdfPageWidth = pdfOriginalWH . find (
98
+ ( data ) => data . pageNumber === pageNumber
99
+ ) ;
100
+ const containerScale = containerWH . width / getPdfPageWidth ?. width || 1 ;
97
101
98
102
const posHeight = pos . Height || defaultWidthHeight ( pos . type ) . height ;
99
103
if ( signYourself ) {
@@ -189,6 +193,7 @@ function RenderPdf({
189
193
scale = { scale }
190
194
containerWH = { containerWH }
191
195
pdfOriginalWH = { pdfOriginalWH }
196
+ pageNumber = { pageNumber }
192
197
/>
193
198
</ React . Fragment >
194
199
)
@@ -248,9 +253,8 @@ function RenderPdf({
248
253
ref = { drop }
249
254
id = "container"
250
255
>
251
- { isLoadPdf &&
252
- containerWH ?. width &&
253
- pdfOriginalWH ?. width &&
256
+ { containerWH ?. width &&
257
+ pdfOriginalWH . length > 0 &&
254
258
( pdfRequest
255
259
? signerPos . map ( ( data , key ) => {
256
260
return (
@@ -315,6 +319,7 @@ function RenderPdf({
315
319
scale = { scale }
316
320
containerWH = { containerWH }
317
321
pdfOriginalWH = { pdfOriginalWH }
322
+ pageNumber = { pageNumber }
318
323
/>
319
324
</ React . Fragment >
320
325
) ;
@@ -367,6 +372,7 @@ function RenderPdf({
367
372
}
368
373
scale = { scale }
369
374
pdfOriginalWH = { pdfOriginalWH }
375
+ pageNumber = { pageNumber }
370
376
/>
371
377
)
372
378
) ;
@@ -379,7 +385,7 @@ function RenderPdf({
379
385
< div className = "flex items-center justify-center" >
380
386
< Document
381
387
onLoadError = { ( ) => {
382
- setPdfLoadFail ( true ) ;
388
+ setPdfLoad ( false ) ;
383
389
} }
384
390
loading = { "Loading Document.." }
385
391
onLoadSuccess = { pageDetails }
@@ -398,10 +404,6 @@ function RenderPdf({
398
404
}
399
405
>
400
406
< Page
401
- onLoadSuccess = { ( { height } ) => {
402
- setPdfRenderHeight && setPdfRenderHeight ( height ) ;
403
- setIsLoadPdf ( true ) ;
404
- } }
405
407
key = { index }
406
408
pageNumber = { pageNumber }
407
409
width = { containerWH . width }
@@ -432,9 +434,9 @@ function RenderPdf({
432
434
ref = { drop }
433
435
id = "container"
434
436
>
435
- { isLoadPdf &&
437
+ { pdfLoad &&
436
438
containerWH ?. width &&
437
- pdfOriginalWH ?. width &&
439
+ pdfOriginalWH . length > 0 &&
438
440
( pdfRequest //pdf request sign flow
439
441
? signerPos ?. map ( ( data , key ) => {
440
442
return (
@@ -499,6 +501,7 @@ function RenderPdf({
499
501
scale = { scale }
500
502
containerWH = { containerWH }
501
503
pdfOriginalWH = { pdfOriginalWH }
504
+ pageNumber = { pageNumber }
502
505
/>
503
506
</ React . Fragment >
504
507
) ;
@@ -556,6 +559,7 @@ function RenderPdf({
556
559
scale = { scale }
557
560
containerWH = { containerWH }
558
561
pdfOriginalWH = { pdfOriginalWH }
562
+ pageNumber = { pageNumber }
559
563
/>
560
564
</ React . Fragment >
561
565
) ;
@@ -567,11 +571,7 @@ function RenderPdf({
567
571
{ /* this component for render pdf document is in middle of the component */ }
568
572
< Document
569
573
onLoadError = { ( ) => {
570
- const load = {
571
- status : false ,
572
- type : "failed"
573
- } ;
574
- setPdfLoadFail ( load ) ;
574
+ pdfLoad ( false ) ;
575
575
} }
576
576
loading = { "Loading Document.." }
577
577
onLoadSuccess = { pageDetails }
@@ -590,10 +590,6 @@ function RenderPdf({
590
590
}
591
591
>
592
592
< Page
593
- onLoadSuccess = { ( { height } ) => {
594
- setPdfRenderHeight && setPdfRenderHeight ( height ) ;
595
- setIsLoadPdf ( true ) ;
596
- } }
597
593
key = { index }
598
594
width = { containerWH . width }
599
595
scale = { scale || 1 }
0 commit comments