fix: incompatible pdf issue and signturetype issues

This commit is contained in:
prafull-opensignlabs
2024-11-07 14:12:01 +05:30
parent 851ea24be4
commit 9915a700bb
7 changed files with 75 additions and 76 deletions
+16 -26
View File
@@ -125,7 +125,6 @@ function SignPad(props) {
props?.onSaveSign(signatureType);
}
}
setPenColor("blue");
} else {
setIsSignImg("");
@@ -136,7 +135,7 @@ function SignPad(props) {
props?.setIsImageSelect(false);
setIsDefaultSign(false);
props?.setImage();
setIsTab("draw");
handleTab();
setSignValue("");
props?.setIsStamp(false);
}}
@@ -310,6 +309,19 @@ function SignPad(props) {
</div>
);
};
// `handleCancelBtn` function trigger when user click on cross button
const handleCancelBtn = () => {
setPenColor("blue");
props?.setIsSignPad(false);
props?.setIsInitial(false);
props?.setIsImageSelect(false);
setIsDefaultSign(false);
props?.setImage();
handleTab();
setSignValue("");
props?.setIsStamp(false);
};
return (
<div>
{props?.isSignPad && (
@@ -443,18 +455,7 @@ function SignPad(props) {
</div>
<div
className="text-[1.5rem] cursor-pointer"
onClick={() => {
setPenColor("blue");
props?.setIsSignPad(false);
props?.setIsInitial(false);
props?.setIsImageSelect(false);
setIsDefaultSign(false);
props?.setImage();
setIsTab("draw");
setSignatureType("draw");
setSignValue("");
props?.setIsStamp(false);
}}
onClick={handleCancelBtn}
>
&times;
</div>
@@ -657,18 +658,7 @@ function SignPad(props) {
</div>
<div
className="text-[1.5rem] cursor-pointer"
onClick={() => {
setPenColor("blue");
props?.setIsSignPad(false);
props?.setIsInitial(false);
props?.setIsImageSelect(false);
setIsDefaultSign(false);
props?.setImage();
setIsTab("draw");
setSignatureType("draw");
setSignValue("");
props?.setIsStamp(false);
}}
onClick={handleCancelBtn}
>
&times;
</div>
+23 -21
View File
@@ -637,10 +637,10 @@ export const signPdfFun = async (
return { status: "error", message: "something went wrong." };
}
}
//change image width and height to 100/40 in png base64
const getNewse64 = await changeImageWH(base64Sign);
//remove suffiix of base64
const suffixbase64 = getNewse64 && getNewse64.split(",").pop();
//change image width and height to 300/120 in png base64
const imagebase64 = await changeImageWH(base64Sign);
//remove suffiix of base64 (without type)
const suffixbase64 = imagebase64 && imagebase64.split(",").pop();
const params = {
mailProvider: activeMailAdapter,
@@ -1169,10 +1169,7 @@ export function onSaveSign(
Height: posHeight,
SignUrl: signatureImg,
signatureType: type && type,
options: {
...position.options,
response: signatureImg
}
options: { ...position.options, response: signatureImg }
};
}
return position;
@@ -1382,11 +1379,16 @@ export const multiSignEmbed = async (
const form = pdfDoc.getForm();
const page = pages[pageNo - 1];
const images = await Promise.all(
widgetsPositionArr.map(async (url) => {
let signUrl = url.SignUrl && url.SignUrl;
if (signUrl) {
const res = await fetch(signUrl);
return res.arrayBuffer();
widgetsPositionArr.map(async (widget) => {
// `SignUrl` this is wrong nomenclature and maintain for older code in this options we save base64 of signature image from sign pad
let signbase64 = widget.SignUrl && widget.SignUrl;
if (signbase64) {
let arr = signbase64.split(","),
mime = arr[0].match(/:(.*?);/)[1];
const res = await fetch(signbase64);
const arrayBuffer = await res.arrayBuffer();
const obj = { mimetype: mime, arrayBuffer: arrayBuffer };
return obj;
}
})
);
@@ -1397,17 +1399,17 @@ export const multiSignEmbed = async (
if (
["signature", "stamp", "initials", "image"].includes(position.type)
) {
if (position.ImageType && position.ImageType === "image/jpeg") {
img = await pdfDoc.embedJpg(images[id]);
if (images[id].mimetype === "image/png") {
img = await pdfDoc.embedPng(images[id].arrayBuffer);
} else {
img = await pdfDoc.embedPng(images[id]);
img = await pdfDoc.embedJpg(images[id].arrayBuffer);
}
} else if (!position.type) {
// to handle old widget when only stamp and signature are exists
if (position.ImageType && position.ImageType === "image/jpeg") {
img = await pdfDoc.embedJpg(images[id]);
if (images[id].mimetype === "image/png") {
img = await pdfDoc.embedPng(images[id].arrayBuffer);
} else {
img = await pdfDoc.embedPng(images[id]);
img = await pdfDoc.embedJpg(images[id].arrayBuffer);
}
}
let widgetWidth, widgetHeight;
@@ -1992,7 +1994,7 @@ export const getAppLogo = async () => {
}
};
export const getTenantDetails = async (objectId, jwttoken) => {
export const getTenantDetails = async (objectId, jwttoken, contactId) => {
try {
const url = `${localStorage.getItem("baseUrl")}functions/gettenant`;
const parseAppId = localStorage.getItem("parseAppId");
@@ -2000,7 +2002,7 @@ export const getTenantDetails = async (objectId, jwttoken) => {
const token = jwttoken
? { jwttoken: jwttoken }
: { "X-Parse-Session-Token": accesstoken };
const data = jwttoken ? {} : { userId: objectId };
const data = jwttoken ? {} : { userId: objectId, contactId: contactId };
const res = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
+1 -1
View File
@@ -156,7 +156,7 @@ const sidebarList = [
objectId: "webhook"
},
{
icon: "fa-light fa-pen-fancy",
icon: "fa-light fa-sliders",
title: "Preferences",
target: "_self",
pageType: "",
+9 -5
View File
@@ -136,10 +136,10 @@ const ManageSign = () => {
const replaceSpace = sanitizeFileName(sanitizename);
let file;
if (signature) {
file = base64StringtoFile(signature, `${replaceSpace}_sign.png`);
file = base64StringtoFile(signature, `${replaceSpace}_sign`);
} else {
if (image && !isUrl) {
file = base64StringtoFile(image, `${replaceSpace}__sign.png`);
file = base64StringtoFile(image, `${replaceSpace}__sign`);
}
}
let imgUrl;
@@ -153,12 +153,12 @@ const ManageSign = () => {
let initialFile;
if (Initials) {
initialFile = base64StringtoFile(Initials, `${replaceSpace}_sign.png`);
initialFile = base64StringtoFile(Initials, `${replaceSpace}_sign`);
} else {
if (imgInitials && !isInitialsUrl) {
initialFile = base64StringtoFile(
imgInitials,
`${replaceSpace}__sign.png`
`${replaceSpace}__sign`
);
}
}
@@ -179,14 +179,18 @@ const ManageSign = () => {
};
function base64StringtoFile(base64String, filename) {
let arr = base64String.split(","),
// type of uploaded image
mime = arr[0].match(/:(.*?);/)[1],
// decode base64
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
const ext = mime.split("/").pop();
const name = `${filename}.${ext}`;
return new File([u8arr], name, { type: mime });
}
const uploadFile = async (file) => {
+21 -18
View File
@@ -378,29 +378,29 @@ function PdfRequestFiles(props) {
return;
}
};
const fetchTenantDetails = async () => {
const fetchTenantDetails = async (contactId) => {
const user = JSON.parse(
localStorage.getItem(
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
)
);
if (user) {
try {
const tenantDetails = await getTenantDetails(user?.objectId);
if (tenantDetails && tenantDetails === "user does not exist!") {
alert(t("user-not-exist"));
} else if (tenantDetails) {
const signatureType = tenantDetails?.SignatureType || [];
const filterSignTypes = signatureType?.filter(
(x) => x.enabled === true
);
return filterSignTypes;
}
} catch (e) {
try {
const tenantDetails = await getTenantDetails(
user?.objectId, // userId
"", // jwttoken
contactId // contactId
);
if (tenantDetails && tenantDetails === "user does not exist!") {
alert(t("user-not-exist"));
} else if (tenantDetails) {
const signatureType = tenantDetails?.SignatureType || [];
const filterSignTypes = signatureType?.filter(
(x) => x.enabled === true
);
return filterSignTypes;
}
} else {
} catch (e) {
alert(t("user-not-exist"));
}
};
@@ -412,7 +412,10 @@ function PdfRequestFiles(props) {
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
);
const jsonSender = JSON.parse(senderUser);
const tenantSignTypes = await fetchTenantDetails();
const contactId = jsonSender?.objectId
? ""
: contactBookId || signerObjectId || "";
const tenantSignTypes = await fetchTenantDetails(contactId);
// `currUserId` will be contactId or extUserId
let currUserId;
//getting document details
@@ -453,7 +456,7 @@ function PdfRequestFiles(props) {
currUserId = getCurrentSigner?.objectId
? getCurrentSigner.objectId
: contactBookId || signerObjectId || "";
: contactBookId || signerObjectId || ""; //signerObjectId is contactBookId refer from public template flow
if (isEnableSubscription) {
await checkIsSubscribed(
documentData[0]?.ExtUserPtr?.objectId,
+1 -1
View File
@@ -73,7 +73,7 @@ const Preferences = () => {
const params = { SignatureType: signatureType };
const updateRes = await Parse.Cloud.run("updatesignaturetype", params);
if (updateRes) {
setIsAlert({ type: "danger", msg: "Saved successfully." });
setIsAlert({ type: "success", msg: "Saved successfully." });
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
}
} catch (err) {
+4 -4
View File
@@ -755,10 +755,10 @@ function SignYourSelf() {
alert(t("something-went-wrong-mssg"));
}
}
//change image width and height to 100/40 in png base64
const getNewse64 = await changeImageWH(base64Sign);
//remove suffiix of base64
const suffixbase64 = getNewse64 && getNewse64.split(",").pop();
//change image width and height to 300/120 in png base64
const imagebase64 = await changeImageWH(base64Sign);
//remove suffiix of base64 (without type)
const suffixbase64 = imagebase64 && imagebase64.split(",").pop();
const params = {
pdfFile: base64Url,
docId: documentId,