@@ -315,138 +315,139 @@ function PdfRequestFiles() {
315
315
const pdfDoc = await PDFDocument . load ( existingPdfBytes , {
316
316
ignoreEncryption : true
317
317
} ) ;
318
- let pdfBase64 ;
318
+ // let pdfBase64;
319
319
320
320
//checking if signature is only one then send image url in jpeg formate to server
321
- if ( pngUrl . length === 1 && pngUrl [ 0 ] . pos . length === 1 ) {
322
- if ( isDocId ) {
323
- try {
324
- pdfBase64 = await getBase64FromUrl ( pdfUrl ) ;
325
- } catch ( err ) {
326
- console . log ( err ) ;
327
- }
328
- } else {
329
- //embed document's object id to all pages in pdf document
330
- try {
331
- await embedDocId ( pdfDoc , documentId , allPages ) ;
332
- } catch ( err ) {
333
- console . log ( err ) ;
334
- }
335
- try {
336
- pdfBase64 = await pdfDoc . saveAsBase64 ( {
337
- useObjectStreams : false
338
- } ) ;
339
- } catch ( err ) {
340
- console . log ( err ) ;
341
- }
342
- }
343
- for ( let pngData of pngUrl ) {
344
- const imgUrlList = pngData . pos ;
345
- const pageNo = pngData . pageNumber ;
346
- imgUrlList . map ( async ( data ) => {
347
- //cheking signUrl is defau;t signature url of custom url
348
- let ImgUrl = data . SignUrl ;
349
- const checkUrl = urlValidator ( ImgUrl ) ;
350
- //if default signature url then convert it in base 64
351
- if ( checkUrl ) {
352
- ImgUrl = await getBase64FromIMG ( ImgUrl + "?get" ) ;
353
- }
354
- //function for called convert png signatre to jpeg in base 64
355
- convertPNGtoJPEG ( ImgUrl )
356
- . then ( ( jpegBase64Data ) => {
357
- const removeBase64Fromjpeg = "data:image/jpeg;base64," ;
358
- const newImgUrl = jpegBase64Data . replace (
359
- removeBase64Fromjpeg ,
360
- ""
361
- ) ;
362
-
363
- //function for call to embed signature in pdf and get digital signature pdf
364
- signPdfFun (
365
- newImgUrl ,
366
- documentId ,
367
- signerObjectId ,
368
- pdfOriginalWidth ,
369
- pngUrl ,
370
- containerWH ,
371
- setIsAlert ,
372
- data ,
373
- pdfBase64 ,
374
- pageNo
375
- )
376
- . then ( ( res ) => {
377
- if ( res && res . status === "success" ) {
378
- setPdfUrl ( res . data ) ;
379
- setIsSigned ( true ) ;
380
- setSignedSigners ( [ ] ) ;
381
- setUnSignedSigners ( [ ] ) ;
382
- getDocumentDetails ( ) ;
383
- } else {
384
- setIsAlert ( {
385
- isShow : true ,
386
- alertMessage : "something went wrong"
387
- } ) ;
388
- }
389
- } )
390
- . catch ( ( err ) => {
391
- setIsAlert ( {
392
- isShow : true ,
393
- alertMessage : "something went wrong"
394
- } ) ;
395
- } ) ;
396
- } )
397
- . catch ( ( error ) => {
398
- console . error ( "Error:" , error ) ;
399
- } ) ;
400
- } ) ;
401
- }
402
- }
403
- //else if signature is more than one then embed all sign with the use of pdf-lib
404
- else if ( pngUrl . length > 0 && pngUrl [ 0 ] . pos . length > 0 ) {
405
- const flag = false ;
406
- //embed document's object id to all pages in pdf document
321
+ // if (pngUrl.length === 1 && pngUrl[0].pos.length === 1) {
322
+ // if (isDocId) {
323
+ // try {
324
+ // pdfBase64 = await getBase64FromUrl(pdfUrl);
325
+ // } catch (err) {
326
+ // console.log(err);
327
+ // }
328
+ // } else {
329
+ // //embed document's object id to all pages in pdf document
330
+ // try {
331
+ // await embedDocId(pdfDoc, documentId, allPages);
332
+ // } catch (err) {
333
+ // console.log(err);
334
+ // }
335
+ // try {
336
+ // pdfBase64 = await pdfDoc.saveAsBase64({
337
+ // useObjectStreams: false
338
+ // });
339
+ // } catch (err) {
340
+ // console.log(err);
341
+ // }
342
+ // }
343
+ // for (let pngData of pngUrl) {
344
+ // const imgUrlList = pngData.pos;
345
+ // const pageNo = pngData.pageNumber;
346
+ // imgUrlList.map(async (data) => {
347
+ // //cheking signUrl is defau;t signature url of custom url
348
+ // let ImgUrl = data.SignUrl;
349
+ // const checkUrl = urlValidator(ImgUrl);
350
+ // //if default signature url then convert it in base 64
351
+ // if (checkUrl) {
352
+ // ImgUrl = await getBase64FromIMG(ImgUrl + "?get");
353
+ // }
354
+ // //function for called convert png signatre to jpeg in base 64
355
+ // convertPNGtoJPEG(ImgUrl)
356
+ // .then((jpegBase64Data) => {
357
+ // const removeBase64Fromjpeg = "data:image/jpeg;base64,";
358
+ // const newImgUrl = jpegBase64Data.replace(
359
+ // removeBase64Fromjpeg,
360
+ // ""
361
+ // );
362
+
363
+ // //function for call to embed signature in pdf and get digital signature pdf
364
+ // signPdfFun(
365
+ // newImgUrl,
366
+ // documentId,
367
+ // signerObjectId,
368
+ // pdfOriginalWidth,
369
+ // pngUrl,
370
+ // containerWH,
371
+ // setIsAlert,
372
+ // data,
373
+ // pdfBase64,
374
+ // pageNo
375
+ // )
376
+ // .then((res) => {
377
+ // if (res && res.status === "success") {
378
+ // setPdfUrl(res.data);
379
+ // setIsSigned(true);
380
+ // setSignedSigners([]);
381
+ // setUnSignedSigners([]);
382
+ // getDocumentDetails();
383
+ // } else {
384
+ // setIsAlert({
385
+ // isShow: true,
386
+ // alertMessage: "something went wrong"
387
+ // });
388
+ // }
389
+ // })
390
+ // .catch((err) => {
391
+ // setIsAlert({
392
+ // isShow: true,
393
+ // alertMessage: "something went wrong"
394
+ // });
395
+ // });
396
+ // })
397
+ // .catch((error) => {
398
+ // console.error("Error:", error);
399
+ // });
400
+ // });
401
+ // }
402
+ // }
403
+ // //else if signature is more than one then embed all sign with the use of pdf-lib
404
+ // else if (pngUrl.length > 0 && pngUrl[0].pos.length > 0) {
405
+ const flag = false ;
406
+ //embed document's object id to all pages in pdf document
407
+ if ( ! isDocId ) {
407
408
await embedDocId ( pdfDoc , documentId , allPages ) ;
408
- //embed multi signature in pdf
409
- const pdfBytes = await multiSignEmbed (
410
- pngUrl ,
411
- pdfDoc ,
409
+ }
410
+ //embed multi signature in pdf
411
+ const pdfBytes = await multiSignEmbed (
412
+ pngUrl ,
413
+ pdfDoc ,
414
+ pdfOriginalWidth ,
415
+ flag ,
416
+ containerWH
417
+ ) ;
418
+ //function for call to embed signature in pdf and get digital signature pdf
419
+ try {
420
+ const res = await signPdfFun (
421
+ pdfBytes ,
422
+ documentId ,
423
+ signerObjectId ,
412
424
pdfOriginalWidth ,
413
- flag ,
414
- containerWH
425
+ pngUrl ,
426
+ containerWH ,
427
+ setIsAlert
415
428
) ;
416
-
417
- //function for call to embed signature in pdf and get digital signature pdf
418
- try {
419
- const res = await signPdfFun (
420
- pdfBytes ,
421
- documentId ,
422
- signerObjectId ,
423
- pdfOriginalWidth ,
424
- pngUrl ,
425
- containerWH ,
426
- setIsAlert
427
- ) ;
428
- if ( res && res . status === "success" ) {
429
- setPdfUrl ( res . data ) ;
430
- setIsSigned ( true ) ;
431
- setSignedSigners ( [ ] ) ;
432
- setUnSignedSigners ( [ ] ) ;
433
- getDocumentDetails ( ) ;
434
- } else {
435
- setIsAlert ( {
436
- isShow : true ,
437
- alertMessage : "something went wrong"
438
- } ) ;
439
- }
440
- } catch ( err ) {
429
+ if ( res && res . status === "success" ) {
430
+ setPdfUrl ( res . data ) ;
431
+ setIsSigned ( true ) ;
432
+ setSignedSigners ( [ ] ) ;
433
+ setUnSignedSigners ( [ ] ) ;
434
+ getDocumentDetails ( ) ;
435
+ } else {
441
436
setIsAlert ( {
442
437
isShow : true ,
443
438
alertMessage : "something went wrong"
444
439
} ) ;
445
440
}
441
+ } catch ( err ) {
442
+ setIsAlert ( {
443
+ isShow : true ,
444
+ alertMessage : "something went wrong"
445
+ } ) ;
446
446
}
447
-
448
- setIsSignPad ( false ) ;
449
447
}
448
+
449
+ setIsSignPad ( false ) ;
450
+ // }
450
451
} else {
451
452
setIsAlert ( {
452
453
isShow : true ,
@@ -626,7 +627,7 @@ function PdfRequestFiles() {
626
627
627
628
return (
628
629
< DndProvider backend = { HTML5Backend } >
629
- < Title title = { "Request Sign" } />
630
+ < Title title = { "Request Sign" } />
630
631
{ isLoading . isLoad ? (
631
632
< Loader isLoading = { isLoading } />
632
633
) : handleError ? (
0 commit comments