Skip to content

Commit 28a2a11

Browse files
authored
Merge pull request #682 from OpenSignLabs/signPdf
fix: issue of showing currently encrypted file not supported when try to sign document
2 parents 534dc3d + 0738282 commit 28a2a11

File tree

4 files changed

+57
-36
lines changed

4 files changed

+57
-36
lines changed

apps/OpenSign/src/components/pdf/SignPad.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ function SignPad({
214214
const fontfamily = fontStyle
215215
? fontStyle
216216
: fontSelect
217-
? fontSelect
218-
: "Fasthand";
217+
? fontSelect
218+
: "Fasthand";
219219

220220
//creating span for getting text content width
221221
const span = document.createElement("span");
@@ -267,10 +267,10 @@ function SignPad({
267267
key === 0 && penColor === "blue"
268268
? "2px solid blue"
269269
: key === 1 && penColor === "red"
270-
? "2px solid red"
271-
: key === 2 && penColor === "black"
272-
? "2px solid black"
273-
: "2px solid white"
270+
? "2px solid red"
271+
: key === 2 && penColor === "black"
272+
? "2px solid black"
273+
: "2px solid white"
274274
}}
275275
onClick={() => {
276276
props?.convertToImg &&
@@ -536,7 +536,6 @@ function SignPad({
536536
style={{
537537
border: "1.3px solid #007bff",
538538
borderRadius: "2px",
539-
540539
display: "flex",
541540
flexDirection: "column",
542541
justifyContent: "center",
@@ -553,7 +552,7 @@ function SignPad({
553552
type="file"
554553
onChange={onImageChange}
555554
className="filetype"
556-
accept="image/*"
555+
accept="image/png,image/jpeg"
557556
ref={imageRef}
558557
hidden
559558
/>

apps/OpenSign/src/constant/Utils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,22 @@ export const signPdfFun = async (
561561
isCustomCompletionMail = true;
562562
}
563563
}
564-
564+
565+
// below for loop is used to get first signature of user to send if to signpdf
566+
// for adding it in completion certificate
565567
let getSignature;
566568
for (let item of xyPosition) {
567569
const typeExist = item.pos.some((data) => data?.type);
568570
if (typeExist) {
569-
getSignature = item.pos.filter((data) => data?.type === "signature");
571+
getSignature = item.pos.find((data) => data?.type === "signature");
572+
break;
570573
} else {
571-
getSignature = item.pos.filter((data) => !data.isStamp);
574+
getSignature = item.pos.find((data) => !data.isStamp);
575+
break;
572576
}
573577
}
574-
let base64Sign = getSignature[0].SignUrl;
578+
579+
let base64Sign = getSignature.SignUrl;
575580
//check https type signature (default signature exist) then convert in base64
576581
const isUrl = base64Sign.includes("https");
577582
if (isUrl) {
@@ -1344,8 +1349,8 @@ export const multiSignEmbed = async (
13441349
position.type === radioButtonWidget
13451350
? 10
13461351
: position.type === "checkbox"
1347-
? 10
1348-
: newUpdateHeight;
1352+
? 10
1353+
: newUpdateHeight;
13491354
const newHeight = ind ? (ind > 0 ? widgetHeight : 0) : widgetHeight;
13501355

13511356
if (signyourself) {

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ function PdfRequestFiles() {
647647
const existingPdfBytes = pdfArrayBuffer;
648648
try {
649649
const pdfDoc = await PDFDocument.load(existingPdfBytes);
650-
651650
const isSignYourSelfFlow = false;
652651
const extUserPtr = pdfDetails[0].ExtUserPtr;
653652
const HeaderDocId = extUserPtr?.HeaderDocId;
@@ -843,10 +842,18 @@ function PdfRequestFiles() {
843842
}
844843
} catch (err) {
845844
setIsUiLoading(false);
846-
setIsAlert({
847-
isShow: true,
848-
alertMessage: `Currently encrypted pdf files are not supported.`
849-
});
845+
if (err && err.message.includes("is encrypted.")) {
846+
setIsAlert({
847+
isShow: true,
848+
alertMessage: `Currently encrypted pdf files are not supported.`
849+
});
850+
} else {
851+
console.log("err in request signing", err);
852+
setIsAlert({
853+
isShow: true,
854+
alertMessage: `Something went wrong.`
855+
});
856+
}
850857
}
851858
}
852859
setIsSignPad(false);
@@ -1238,9 +1245,9 @@ function PdfRequestFiles() {
12381245
isDecline.currnt === "Sure"
12391246
? "Are you sure want to decline this document ?"
12401247
: isDecline.currnt === "YouDeclined"
1241-
? "You have declined this document!"
1242-
: isDecline.currnt === "another" &&
1243-
"You can not sign this document as it has been declined/revoked."
1248+
? "You have declined this document!"
1249+
: isDecline.currnt === "another" &&
1250+
"You can not sign this document as it has been declined/revoked."
12441251
}
12451252
footerMessage={isDecline.currnt === "Sure"}
12461253
declineDoc={declineDoc}

apps/OpenSign/src/pages/SignyourselfPdf.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,13 @@ function SignYourSelf() {
480480
Width: widgetTypeExist
481481
? calculateInitialWidthHeight(dragTypeValue, widgetValue).getWidth
482482
: dragTypeValue === "initials"
483-
? defaultWidthHeight(dragTypeValue).width
484-
: "",
483+
? defaultWidthHeight(dragTypeValue).width
484+
: "",
485485
Height: widgetTypeExist
486486
? calculateInitialWidthHeight(dragTypeValue, widgetValue).getHeight
487487
: dragTypeValue === "initials"
488-
? defaultWidthHeight(dragTypeValue).height
489-
: "",
488+
? defaultWidthHeight(dragTypeValue).height
489+
: "",
490490
options: addWidgetOptions(dragTypeValue)
491491
};
492492

@@ -649,9 +649,7 @@ function SignYourSelf() {
649649
const existingPdfBytes = pdfArrayBuffer;
650650
// Load a PDFDocument from the existing PDF bytes
651651
try {
652-
const pdfDoc = await PDFDocument.load(existingPdfBytes, {
653-
ignoreEncryption: true
654-
});
652+
const pdfDoc = await PDFDocument.load(existingPdfBytes);
655653
const isSignYourSelfFlow = true;
656654
const extUserPtr = pdfDetails[0].ExtUserPtr;
657655
const HeaderDocId = extUserPtr?.HeaderDocId;
@@ -672,10 +670,18 @@ function SignYourSelf() {
672670
await signPdfFun(pdfBytes, documentId);
673671
} catch (err) {
674672
setIsUiLoading(false);
675-
setIsAlert({
676-
isShow: true,
677-
alertMessage: `Currently encrypted pdf files are not supported.`
678-
});
673+
if (err && err.message.includes("is encrypted.")) {
674+
setIsAlert({
675+
isShow: true,
676+
alertMessage: `Currently encrypted pdf files are not supported.`
677+
});
678+
} else {
679+
console.log("err in signing", err);
680+
setIsAlert({
681+
isShow: true,
682+
alertMessage: `Something went wrong.`
683+
});
684+
}
679685
}
680686
}
681687
} catch (err) {
@@ -703,16 +709,20 @@ function SignYourSelf() {
703709
isCustomCompletionMail = true;
704710
}
705711
}
712+
// below for loop is used to get first signature of user to send if to signpdf
713+
// for adding it in completion certificate
706714
let getSignature;
707715
for (let item of xyPostion) {
708716
const typeExist = item.pos.some((data) => data?.type);
709717
if (typeExist) {
710-
getSignature = item.pos.filter((data) => data?.type === "signature");
718+
getSignature = item.pos.find((data) => data?.type === "signature");
719+
break;
711720
} else {
712-
getSignature = item.pos.filter((data) => !data.isStamp);
721+
getSignature = item.pos.find((data) => !data.isStamp);
722+
break;
713723
}
714724
}
715-
let base64Sign = getSignature[0].SignUrl;
725+
let base64Sign = getSignature.SignUrl;
716726
//check https type signature (default signature exist) then convert in base64
717727
const isUrl = base64Sign.includes("https");
718728
if (isUrl) {

0 commit comments

Comments
 (0)