@@ -267,8 +262,7 @@ function SignPad({
style={{
width: "100%",
height: "100%",
- background: "rgb(255, 255, 255)",
- objectFit: "contain",
+ objectFit: "contain"
}}
src={defaultSign}
/>
@@ -282,13 +276,12 @@ function SignPad({
imageRef.current.click()}
@@ -300,7 +293,6 @@ function SignPad({
accept="image/*"
ref={imageRef}
hidden
- // style={{ display: "none" }}
/>
Upload
@@ -309,24 +301,25 @@ function SignPad({
<>
@@ -336,36 +329,11 @@ function SignPad({
)
) : (
<>
- {/* {isSignImg ? (
-
-

-
- ) : ( */}
@@ -373,17 +341,16 @@ function SignPad({
}
dotSize={1}
/>
- {/* )} */}
-
+
{allColor.map((data, key) => {
return (
![]()
{
if (key === 0) {
@@ -414,60 +381,14 @@ function SignPad({
width={20}
height={20}
/>
- //
);
})}
-
>
)}
-
- {/*
- {!isStamp && !isImageSelect && (
-
- )}
-
-
- */}
);
diff --git a/microfrontends/SignDocuments/src/Component/placeHolderSign.js b/microfrontends/SignDocuments/src/Component/placeHolderSign.js
index 6d0a95b65..8d1eb8a54 100644
--- a/microfrontends/SignDocuments/src/Component/placeHolderSign.js
+++ b/microfrontends/SignDocuments/src/Component/placeHolderSign.js
@@ -65,6 +65,7 @@ function PlaceHolderSign() {
const [isShowEmail, setIsShowEmail] = useState(false);
const [selectedEmail, setSelectedEmail] = useState(false);
const [isResize, setIsResize] = useState(false);
+ const [isAlreadyPlace, setIsAlreadyPlace] = useState(false);
const [pdfLoadFail, setPdfLoadFail] = useState({
status: false,
type: "load"
@@ -181,8 +182,12 @@ function PlaceHolderSign() {
//getting document details
const documentData = await contractDocument(documentId);
if (documentData && documentData.length > 0) {
+ const alreadyPlaceholder =
+ documentData[0].Placeholders && documentData[0].Placeholders;
+ if (alreadyPlaceholder && alreadyPlaceholder.length > 0) {
+ setIsAlreadyPlace(true);
+ }
setPdfDetails(documentData);
-
const currEmail = documentData[0].ExtUserPtr.Email;
const filterCurrEmail = documentData[0].Signers.filter(
(data) => data.Email === currEmail
@@ -916,6 +921,7 @@ function PlaceHolderSign() {
)}
+
{
@@ -92,8 +99,7 @@ function EmbedPdfImage() {
: `${localStorage.getItem("UserInformation")}` &&
`${localStorage.getItem("UserInformation")}`;
const jsonSender = JSON.parse(senderUser);
- //check isGuestSigner is present in local if yes than handle login flow header in mobile view
- const isGuestSigner = localStorage.getItem("isGuestSigner");
+
useEffect(() => {
getDocumentDetails();
}, []);
@@ -202,7 +208,6 @@ function EmbedPdfImage() {
setIsAlreadySign(alreadySign);
setPdfUrl(documentData[0].SignedUrl);
setSignedPdfData(documentData);
- setCompletePdfData(documentData);
} else if (declined) {
const currentDecline = {
currnt: "another",
@@ -397,7 +402,10 @@ function EmbedPdfImage() {
}
if (checkSignUrl && checkSignUrl.length > 0) {
- alert("Please complete your signature!");
+ setIsAlert({
+ isShow: true,
+ alertMessage: "Please complete your signature!"
+ });
} else {
const loadObj = {
isLoad: true,
@@ -428,9 +436,10 @@ function EmbedPdfImage() {
await embedDocId(pdfDoc, docId, allPages);
pdfBase64 = await pdfDoc.saveAsBase64({ useObjectStreams: false });
}
- for (let i = 0; i < xyPostion.length; i++) {
- const imgUrlList = pngUrl[i].pos;
- const pageNo = pngUrl[i].pageNumber;
+
+ for (let xyData of xyPostion) {
+ const imgUrlList = xyData.pos;
+ const pageNo = xyData.pageNumber;
imgUrlList.map(async (data) => {
//cheking signUrl is defau;t signature url of custom url
let ImgUrl = data.SignUrl;
@@ -456,30 +465,41 @@ function EmbedPdfImage() {
signerUserId,
pdfOriginalWidth,
xyPostion,
+ containerWH,
+ setIsAlert,
data,
pdfBase64,
- pageNo,
- containerWH
+ pageNo
)
.then((res) => {
if (res && res.status === "success") {
getDocumentDetails();
} else {
- alert("something went wrong");
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
}
})
.catch((err) => {
- alert("something went wrong!");
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
});
})
.catch((error) => {
- console.error("Error:", error);
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
});
});
}
}
//else if signature is more than one then embed all sign with the use of pdf-lib
else if (xyPostion.length > 0 && xyPostion[0].pos.length > 0) {
+ const flag = false;
//embed document's object id to all pages in pdf document
await embedDocId(pdfDoc, docId, allPages);
//embed multi signature in pdf
@@ -487,29 +507,35 @@ function EmbedPdfImage() {
pngUrl,
pdfDoc,
pdfOriginalWidth,
- false,
+ flag,
containerWH
);
//function for embed signature in pdf and get digital signature pdf
- signPdfFun(
- pdfBytes,
- docId,
- signerUserId,
- pdfOriginalWidth,
- xyPostion,
- containerWH
- )
- .then((res) => {
- if (res && res.status === "success") {
- getDocumentDetails();
- } else {
- alert("something went wrong!");
- }
- })
- .catch((err) => {
- alert("something went wrong in query");
+ try {
+ const res = await signPdfFun(
+ pdfBytes,
+ docId,
+ signerUserId,
+ pdfOriginalWidth,
+ xyPostion,
+ containerWH,
+ setIsAlert
+ );
+ if (res && res.status === "success") {
+ getDocumentDetails();
+ } else {
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
+ }
+ } catch (err) {
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
});
+ }
}
setIsSignPad(false);
setXyPostion([]);
@@ -524,60 +550,43 @@ function EmbedPdfImage() {
//function for image upload or update
const onImageChange = (event) => {
if (event.target.files && event.target.files[0]) {
- const imageType = event.target.files[0].type;
-
- const reader = new FileReader();
- reader.readAsDataURL(event.target.files[0]);
-
- reader.onloadend = function (e) {
- let width, height;
- const image = new Image();
-
- image.src = e.target.result;
- image.onload = function () {
- width = image.width;
- height = image.height;
- const aspectRatio = 460 / 184;
- const imgR = width / height;
-
- if (imgR > aspectRatio) {
- width = 460;
- height = 460 / imgR;
- } else {
- width = 184 * imgR;
- height = 184;
- }
- setImgWH({ width: width, height: height });
- imageRef.current.style.width = `${width}px`;
- imageRef.current.style.height = `${height}px`;
- };
-
- image.src = reader.result;
-
- setImage({ src: image.src, imgType: imageType });
- };
+ onImageSelect(event, setImgWH, setImage);
}
};
//function for save button to save signature or image url
const saveSign = (isDefaultSign) => {
const signatureImg = isDefaultSign ? defaultSignImg : signature;
+ const signFlag = true;
+ let imgWH = { width: "", height: "" };
setIsSignPad(false);
setIsImageSelect(false);
setImage();
+ if (isDefaultSign) {
+ const img = new Image();
+ img.src = defaultSignImg;
+ if (img.complete) {
+ imgWH = {
+ width: img.width,
+ height: img.height
+ };
+ }
+ }
const getUpdatePosition = onSaveSign(
xyPostion,
index,
signKey,
- signatureImg
+ signatureImg,
+ imgWH,
+ isDefaultSign,
+ signFlag
);
if (getUpdatePosition) {
setXyPostion(getUpdatePosition);
}
};
-
//function for upload stamp image
const saveImage = () => {
const getImage = onSaveImage(xyPostion, index, signKey, imgWH, image);
@@ -615,33 +624,21 @@ function EmbedPdfImage() {
}
})
.catch((err) => {
- console.log("error updating field is decline ", err);
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
});
};
const addDefaultSignature = () => {
- let xyDefaultPos = [];
- for (let i = 0; i < xyPostion.length; i++) {
- const getXYdata = xyPostion[i].pos;
- const getPageNo = xyPostion[i].pageNumber;
- const getPosData = getXYdata;
-
- const addSign = getPosData.map((url, ind) => {
- if (url) {
- return { ...url, SignUrl: defaultSignImg };
- }
- return url;
- });
-
- const newXypos = {
- pageNumber: getPageNo,
- pos: addSign
- };
- xyDefaultPos.push(newXypos);
- }
+ const getXyData = addDefaultSignatureImg(xyPostion, defaultSignImg);
- setXyPostion(xyDefaultPos);
- setIsAlreadySign({ status: false });
+ setXyPostion(getXyData);
+ setAddDefaultSign({
+ isShow: false,
+ alertMessage: ""
+ });
};
//function for update TourStatus
@@ -763,6 +760,20 @@ function EmbedPdfImage() {
declineDoc={declineDoc}
setIsDecline={setIsDecline}
/>
+
+
+
{/* this modal is used for show expired alert */}
Close
- {isAlreadySign.sure && (
-
- )}
{/* this is modal of signature pad */}
@@ -905,6 +904,7 @@ function EmbedPdfImage() {
xyPostion={xyPostion}
setXyPostion={setXyPostion}
setShowAlreadySignDoc={setIsAlreadySign}
+ setIsAlert={setAddDefaultSign}
/>
) : (
diff --git a/microfrontends/SignDocuments/src/css/signature.css b/microfrontends/SignDocuments/src/css/signature.css
index 477159b03..34ed5ea08 100644
--- a/microfrontends/SignDocuments/src/css/signature.css
+++ b/microfrontends/SignDocuments/src/css/signature.css
@@ -8,6 +8,7 @@
.penContainer {
width: 460px;
}
+
.borderResize {
position: absolute;
display: inline-block;
@@ -15,17 +16,20 @@
height: 14px;
}
-.mailBtn{
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
- padding: 3px 15px !important;
- background-color: rgb(79 190 241);
- border: none !important;
- color: white !important;
+
+.mailBtn {
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.18);
+ padding: 3px 15px !important;
+ background-color: rgb(79 190 241);
+ border: none !important;
+ color: white !important;
}
+
.mailBtn:hover {
box-shadow: 0 2px 4px rgba(154, 36, 36, 0.1), 0 2px 4px rgba(0, 0, 0, 0.18);
}
-.emailToast{
+
+.emailToast {
position: absolute;
z-index: 10;
background: #aeedae;
@@ -34,7 +38,7 @@
border-radius: 2px;
}
-
+
.signatureBtn {
border: 1.5px solid #47a3ad;
margin-bottom: 10px;
@@ -162,14 +166,15 @@
.placeholdCloseBtn {
position: absolute;
- right: -9px;
- top: -15px;
+ right: -5px;
+ top: -5px;
border-radius: 100%;
font-size: 10px;
cursor: pointer;
- padding: 0px 5px;
+ padding: 0px 5.1px 1px 5px;
}
-.placeholderBlock{
+
+.placeholderBlock {
padding: 0px;
z-index: 1;
position: absolute;
@@ -179,7 +184,8 @@
background: #daebe0;
text-align: center;
justify-content: center;
- border-width: 0.2px
+ border-width: 0.2px;
+
}
.finishBtn {
diff --git a/microfrontends/SignDocuments/src/utils/Utils.js b/microfrontends/SignDocuments/src/utils/Utils.js
index b12cf2fc1..a1aca4c2e 100644
--- a/microfrontends/SignDocuments/src/utils/Utils.js
+++ b/microfrontends/SignDocuments/src/utils/Utils.js
@@ -1,6 +1,9 @@
import axios from "axios";
import { $ } from "select-dom";
import { rgb } from "pdf-lib";
+
+const isMobile = window.innerWidth < 767;
+
export async function getBase64FromUrl(url) {
const data = await fetch(url);
const blob = await data.blob();
@@ -74,46 +77,49 @@ export function getHostUrl() {
}
}
+export const calculateImgAspectRatio = (imgWH) => {
+ let newWidth, newHeight;
+ const aspectRatio = imgWH.width / imgWH.height;
+ if (aspectRatio === "2.533333333333333") {
+ newWidth = 150;
+ newHeight = 60;
+ } else if (aspectRatio === 1) {
+ newWidth = aspectRatio * 100;
+ newHeight = aspectRatio * 100;
+ } else if (aspectRatio < 1) {
+ newWidth = aspectRatio * 70;
+ newHeight = 70;
+ } else if (aspectRatio < 2) {
+ newWidth = aspectRatio * 100;
+ newHeight = 100;
+ } else if (aspectRatio > 2 && aspectRatio < 4) {
+ newWidth = aspectRatio * 70;
+ newHeight = 70;
+ } else if (aspectRatio > 4) {
+ newWidth = aspectRatio * 40;
+ newHeight = 40;
+ } else if (aspectRatio > 5) {
+ newWidth = aspectRatio * 10;
+ newHeight = 10;
+ }
+ return { newHeight, newWidth };
+};
+
//function for upload stamp or image
export function onSaveImage(xyPostion, index, signKey, imgWH, image) {
const updateFilter = xyPostion[index].pos.filter(
(data, ind) =>
data.key === signKey && data.Width && data.Height && data.SignUrl
);
-
+ let getIMGWH = calculateImgAspectRatio(imgWH);
+ const getXYdata = xyPostion[index].pos;
if (updateFilter.length > 0) {
- let newWidth, newHeight;
- const aspectRatio = imgWH.width / imgWH.height;
-
- const getXYdata = xyPostion[index].pos;
-
- if (aspectRatio === 1) {
- newWidth = aspectRatio * 100;
- newHeight = aspectRatio * 100;
- } else if (aspectRatio < 2) {
- newWidth = aspectRatio * 100;
- newHeight = 100;
- } else if (aspectRatio > 2 && aspectRatio < 4) {
- newWidth = aspectRatio * 70;
- newHeight = 70;
- } else if (aspectRatio > 4) {
- newWidth = aspectRatio * 40;
- newHeight = 40;
- } else if (aspectRatio > 5) {
- newWidth = aspectRatio * 10;
- newHeight = 10;
- }
-
- let getPosData = xyPostion[index].pos.filter(
- (data) => data.key === signKey
- );
-
const addSign = getXYdata.map((url, ind) => {
if (url.key === signKey) {
return {
...url,
- Width: getPosData[0].Width ? getPosData[0].Width : newWidth,
- Height: getPosData[0].Height ? getPosData[0].Height : newHeight,
+ Width: getIMGWH.newWidth,
+ Height: getIMGWH.newHeight,
SignUrl: image.src,
ImageType: image.imgType
};
@@ -128,39 +134,19 @@ export function onSaveImage(xyPostion, index, signKey, imgWH, image) {
return obj;
});
return newUpdateUrl;
- // setXyPostion(newUpdateUrl);
} else {
const getXYdata = xyPostion[index].pos;
let getPosData = xyPostion[index].pos.filter(
(data) => data.key === signKey
);
- const aspectRatio = imgWH.width / imgWH.height;
-
- let newWidth, newHeight;
- if (aspectRatio === 1) {
- newWidth = aspectRatio * 100;
- newHeight = aspectRatio * 100;
- } else if (aspectRatio < 2) {
- newWidth = aspectRatio * 100;
- newHeight = 100;
- } else if (aspectRatio > 2 && aspectRatio < 4) {
- newWidth = aspectRatio * 70;
- newHeight = 70;
- } else if (aspectRatio > 4) {
- newWidth = aspectRatio * 40;
- newHeight = 40;
- } else if (aspectRatio > 5) {
- newWidth = aspectRatio * 10;
- newHeight = 10;
- }
const addSign = getXYdata.map((url, ind) => {
if (url.key === signKey) {
return {
...url,
- Width: getPosData[0].Width ? getPosData[0].Width : newWidth,
- Height: getPosData[0].Height ? getPosData[0].Height : newHeight,
+ Width: getIMGWH.newWidth,
+ Height: getIMGWH.newHeight,
SignUrl: image.src,
ImageType: image.imgType
};
@@ -179,17 +165,46 @@ export function onSaveImage(xyPostion, index, signKey, imgWH, image) {
}
//function for save button to save signature or image url
-export function onSaveSign(xyPostion, index, signKey, signatureImg) {
+export function onSaveSign(
+ xyPostion,
+ index,
+ signKey,
+ signatureImg,
+ imgWH,
+ isDefaultSign,
+ isSign
+) {
let getXYdata = xyPostion[index].pos;
let getPosData = xyPostion[index].pos.filter((data) => data.key === signKey);
+ let getIMGWH;
+ if (isDefaultSign) {
+ getIMGWH = calculateImgAspectRatio(imgWH);
+ }
+
+ const posWidth = isDefaultSign
+ ? getIMGWH.newWidth
+ : isSign && getPosData[0].ImageType
+ ? 150
+ : getPosData[0].Width
+ ? getPosData[0].Width
+ : 150;
+ const posHidth = isDefaultSign
+ ? getIMGWH.newHeight
+ : isSign && getPosData[0].ImageType
+ ? 60
+ : getPosData[0].Height
+ ? getPosData[0].Height
+ : 60;
+
const addSign = getXYdata.map((url, ind) => {
if (url.key === signKey) {
return {
...url,
- Width: getPosData[0].Width ? getPosData[0].Width : 150,
- Height: getPosData[0].Height ? getPosData[0].Height : 60,
- SignUrl: signatureImg
+ Width: posWidth,
+ Height: posHidth,
+ SignUrl: signatureImg,
+ ImageType: "sign"
};
}
return url;
@@ -204,6 +219,78 @@ export function onSaveSign(xyPostion, index, signKey, signatureImg) {
return newUpdateUrl;
}
+//function for add default signature or image for all requested location
+export const addDefaultSignatureImg = (xyPostion, defaultSignImg) => {
+ let imgWH = { width: "", height: "" };
+ const img = new Image();
+ img.src = defaultSignImg;
+ if (img.complete) {
+ imgWH = {
+ width: img.width,
+ height: img.height
+ };
+ }
+ const getIMGWH = calculateImgAspectRatio(imgWH);
+ let xyDefaultPos = [];
+ for (let i = 0; i < xyPostion.length; i++) {
+ const getXYdata = xyPostion[i].pos;
+ const getPageNo = xyPostion[i].pageNumber;
+ const getPosData = getXYdata;
+
+ const addSign = getPosData.map((url, ind) => {
+ if (url) {
+ return {
+ ...url,
+ SignUrl: defaultSignImg,
+ Width: getIMGWH.newWidth,
+ Height: getIMGWH.newHeight,
+ ImageType: "default"
+ };
+ }
+ return url;
+ });
+
+ const newXypos = {
+ pageNumber: getPageNo,
+ pos: addSign
+ };
+ xyDefaultPos.push(newXypos);
+ }
+ return xyDefaultPos;
+};
+
+//function for select image and upload image
+export const onImageSelect = (event, setImgWH, setImage) => {
+ const imageType = event.target.files[0].type;
+ const reader = new FileReader();
+ reader.readAsDataURL(event.target.files[0]);
+
+ reader.onloadend = function (e) {
+ let width, height;
+ const image = new Image();
+
+ image.src = e.target.result;
+ image.onload = function () {
+ width = image.width;
+ height = image.height;
+ const aspectRatio = 460 / 184;
+ const imgR = width / height;
+
+ if (imgR > aspectRatio) {
+ width = 460;
+ height = 460 / imgR;
+ } else {
+ width = 184 * imgR;
+ height = 184;
+ }
+ setImgWH({ width: width, height: height });
+ };
+
+ image.src = reader.result;
+
+ setImage({ src: image.src, imgType: imageType });
+ };
+};
//function for getting document details from contract_Documents class
export const contractDocument = async (documentId) => {
const data = {
@@ -342,7 +429,83 @@ export function modalAlign() {
modal.style.top = window.innerHeight / 3 + "px";
}
}
+export const containerWidth = (pos, scale, signyourself) => {
+ let width;
+ if (signyourself) {
+ if (isMobile) {
+ return pos.Width * scale;
+ } else {
+ return pos.Width;
+ }
+ } else {
+ if (isMobile) {
+ if (pos.isMobile) {
+ width = pos.Width ? pos.Width * scale : 150 * scale;
+ return width;
+ } else {
+ if (pos.IsResize) {
+ width = pos.Width ? pos.Width * scale : 150 * scale;
+ return width;
+ } else {
+ width = pos.Width ? pos.Width : 150;
+ return width;
+ }
+ }
+ } else {
+ if (pos.isMobile) {
+ if (pos.IsResize) {
+ width = pos.Width ? pos.Width : 150;
+ return width;
+ } else {
+ width = pos.Width ? pos.Width * pos.scale : 150 * pos.scale;
+ return width;
+ }
+ } else {
+ width = pos.Width ? pos.Width : 150;
+ return width;
+ }
+ }
+ }
+};
+export const containerHeight = (pos, scale, signyourself) => {
+ let height;
+ if (signyourself) {
+ if (isMobile) {
+ return pos.Height * scale;
+ } else {
+ return pos.Height;
+ }
+ } else {
+ if (isMobile) {
+ if (pos.isMobile) {
+ height = pos.Height ? pos.Height * scale : 60 * scale;
+ return height;
+ } else {
+ if (pos.IsResize) {
+ height = pos.Height ? pos.Height * scale : 60 * scale;
+ return height;
+ } else {
+ height = pos.Height ? pos.Height : 60;
+ return height;
+ }
+ }
+ } else {
+ if (pos.isMobile) {
+ if (pos.IsResize) {
+ height = pos.Height ? pos.Height : 60;
+ return height;
+ } else {
+ height = pos.Height ? pos.Height * pos.scale : 60 * pos.scale;
+ return height;
+ }
+ } else {
+ height = pos.Height ? pos.Height : 60;
+ return height;
+ }
+ }
+ }
+};
//function for embed multiple signature using pdf-lib
export const multiSignEmbed = async (
pngUrl,
@@ -351,9 +514,11 @@ export const multiSignEmbed = async (
signyourself,
containerWH
) => {
- for (let i = 0; i < pngUrl.length; i++) {
- const pageNo = pngUrl[i].pageNumber;
- const imgUrlList = pngUrl[i].pos;
+ for (let item of pngUrl) {
+ const newWidth = containerWH.width;
+ const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
+ const pageNo = item.pageNumber;
+ const imgUrlList = item.pos;
const pages = pdfDoc.getPages();
const page = pages[pageNo - 1];
const images = await Promise.all(
@@ -384,10 +549,9 @@ export const multiSignEmbed = async (
img = await pdfDoc.embedPng(imgData);
}
const imgHeight = imgUrlList[id].Height ? imgUrlList[id].Height : 60;
- const imgWidth = imgUrlList[id].Width ? imgUrlList[id].Width : 150;
- const isMobile = window.innerWidth < 767;
- const newWidth = containerWH.width;
- const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
+ const scaleWidth = containerWidth(imgUrlList[id], scale, signyourself);
+ const scaleHeight = containerHeight(imgUrlList[id], scale, signyourself);
+
const xPos = (pos) => {
if (signyourself) {
if (isMobile) {
@@ -438,13 +602,22 @@ export const multiSignEmbed = async (
const y = pos.yPosition * (pos.scale / scale);
return page.getHeight() - y * scale - imgHeight * scale;
} else {
- return page.getHeight() - y * scale - imgHeight * scale;
+ if (pos.IsResize) {
+ return page.getHeight() - y * scale - imgHeight * scale;
+ } else {
+ return page.getHeight() - y * scale - imgHeight;
+ }
}
} else {
//else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale
if (pos.isMobile) {
- const y = pos.yPosition * pos.scale;
- return page.getHeight() - y - imgHeight;
+ if (pos.IsResize) {
+ const y = pos.yPosition * pos.scale;
+ return page.getHeight() - y - imgHeight;
+ } else {
+ const y = pos.yPosition * pos.scale;
+ return page.getHeight() - y - imgHeight * pos.scale;
+ }
} else {
return page.getHeight() - pos.yPosition - imgHeight;
}
@@ -455,12 +628,14 @@ export const multiSignEmbed = async (
page.drawImage(img, {
x: xPos(imgUrlList[id]),
y: yPos(imgUrlList[id]),
- width: imgWidth * scale,
- height: imgHeight * scale
+ width: scaleWidth,
+ height: scaleHeight
});
});
}
+
const pdfBytes = await pdfDoc.saveAsBase64({ useObjectStreams: false });
+
return pdfBytes;
};
//function for embed document id
@@ -499,14 +674,13 @@ export const handleImageResize = (
setSignerPos,
pdfOriginalWidth,
containerWH,
+ showResize,
setIsResize
) => {
const filterSignerPos = signerPos.filter(
(data) => data.signerObjId === signerId
);
- const isMobile = window.innerWidth < 767;
- const newWidth = containerWH;
- const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
+
if (filterSignerPos.length > 0) {
const getPlaceHolder = filterSignerPos[0].placeHolder;
const getPageNumer = getPlaceHolder.filter(
@@ -523,11 +697,9 @@ export const handleImageResize = (
if (url.key === key) {
return {
...url,
- Width: !url.isMobile ? ref.offsetWidth * scale : ref.offsetWidth,
- Height: !url.isMobile
- ? ref.offsetHeight * scale
- : ref.offsetHeight
- // xPosition: position.x
+ Width: ref.offsetWidth,
+ Height: ref.offsetHeight,
+ IsResize: showResize ? true : false
};
}
return url;
@@ -550,17 +722,14 @@ export const handleImageResize = (
setSignerPos(newUpdateSigner);
} else {
const getXYdata = getPageNumer[0].pos;
-
const getPosData = getXYdata;
-
const addSignPos = getPosData.map((url, ind) => {
if (url.key === key) {
return {
...url,
- Width: !url.isMobile ? ref.offsetWidth * scale : ref.offsetWidth,
- Height: !url.isMobile
- ? ref.offsetHeight * scale
- : ref.offsetHeight
+ Width: ref.offsetWidth,
+ Height: ref.offsetHeight,
+ IsResize: showResize ? true : false
};
}
return url;
@@ -602,9 +771,6 @@ export const handleSignYourselfImageResize = (
const updateFilter = xyPostion[index].pos.filter(
(data) => data.key === key && data.Width && data.Height
);
- const isMobile = window.innerWidth < 767;
- const newWidth = containerWH;
- const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
if (updateFilter.length > 0) {
const getXYdata = xyPostion[index].pos;
@@ -613,11 +779,9 @@ export const handleSignYourselfImageResize = (
if (url.key === key) {
return {
...url,
- // Width: !url.isMobile ? ref.offsetWidth * scale : ref.offsetWidth,
- // Height: !url.isMobile ? ref.offsetHeight * scale : ref.offsetHeight,
Width: ref.offsetWidth,
- Height: ref.offsetHeight
- // xPosition: position.xpos
+ Height: ref.offsetHeight,
+ IsResize: true
};
}
return url;
@@ -640,10 +804,9 @@ export const handleSignYourselfImageResize = (
if (url.key === key) {
return {
...url,
- // Width: !url.isMobile ? ref.offsetWidth * scale : ref.offsetWidth,
- // Height: !url.isMobile ? ref.offsetHeight * scale : ref.offsetHeight
Width: ref.offsetWidth,
- Height: ref.offsetHeight
+ Height: ref.offsetHeight,
+ IsResize: true
};
}
return url;
@@ -666,13 +829,14 @@ export const signPdfFun = async (
signerObjectId,
pdfOriginalWidth,
signerData,
+ containerWH,
+ setIsAlert,
xyPosData,
pdfBase64Url,
- pageNo,
- containerWH
+ pageNo
) => {
- let signgleSign;
- const isMobile = window.innerWidth < 767;
+ let singleSign;
+
const newWidth = containerWH.width;
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
if (signerData && signerData.length === 1 && signerData[0].pos.length === 1) {
@@ -715,24 +879,41 @@ export const signPdfFun = async (
return yPosition;
} else {
const y = pos.yBottom / scale;
-
- yPosition = pos.isDrag
- ? y * scale - height
- : pos.firstYPos
- ? y * scale - height + pos.firstYPos
- : y * scale - height;
- return yPosition;
+ if (pos.IsResize) {
+ yPosition = pos.isDrag
+ ? y * scale - height * scale
+ : pos.firstYPos
+ ? y * scale - height * scale + pos.firstYPos
+ : y * scale - height * scale;
+ return yPosition;
+ } else {
+ yPosition = pos.isDrag
+ ? y * scale - height
+ : pos.firstYPos
+ ? y * scale - height + pos.firstYPos
+ : y * scale - height;
+ return yPosition;
+ }
}
} else {
//else if pos.isMobile true -- placeholder saved from mobile or tablet view then handle position in desktop view divide by scale
if (pos.isMobile) {
const y = pos.yBottom * pos.scale;
- yPosition = pos.isDrag
- ? y - height
- : pos.firstYPos
- ? y - height + pos.firstYPos
- : y - height;
- return yPosition;
+ if (pos.IsResize) {
+ yPosition = pos.isDrag
+ ? y - height
+ : pos.firstYPos
+ ? y - height + pos.firstYPos
+ : y - height;
+ return yPosition;
+ } else {
+ yPosition = pos.isDrag
+ ? y - height * pos.scale
+ : pos.firstYPos
+ ? y - height * pos.scale + pos.firstYPos
+ : y - height * pos.scale;
+ return yPosition;
+ }
} else {
yPosition = pos.isDrag
? pos.yBottom - height
@@ -743,10 +924,9 @@ export const signPdfFun = async (
}
}
};
- const imgWidth = xyPosData.Width ? xyPosData.Width * scale : 150 * scale;
- const imgHeight = height * scale;
+
const bottomY = yBottom(xyPosData);
- signgleSign = {
+ singleSign = {
pdfFile: pdfBase64Url,
docId: documentId,
userId: signerObjectId,
@@ -754,8 +934,8 @@ export const signPdfFun = async (
Base64: base64Url,
Left: xPos(xyPosData),
Bottom: bottomY,
- Width: imgWidth,
- Height: imgHeight,
+ Width: containerWidth(xyPosData, scale),
+ Height: containerHeight(xyPosData, scale),
Page: pageNo
}
};
@@ -764,7 +944,7 @@ export const signPdfFun = async (
signerData.length > 0 &&
signerData[0].pos.length > 0
) {
- signgleSign = {
+ singleSign = {
pdfFile: base64Url,
docId: documentId,
userId: signerObjectId
@@ -772,7 +952,7 @@ export const signPdfFun = async (
}
const response = await axios
- .post(`${localStorage.getItem("baseUrl")}functions/signPdf`, signgleSign, {
+ .post(`${localStorage.getItem("baseUrl")}functions/signPdf`, singleSign, {
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
@@ -782,12 +962,13 @@ export const signPdfFun = async (
.then((Listdata) => {
const json = Listdata.data;
const res = json.result;
- // console.log("res", res);
return res;
})
.catch((err) => {
- console.log("axois err ", err);
- alert("something went wrong");
+ setIsAlert({
+ isShow: true,
+ alertMessage: "something went wrong"
+ });
});
return response;