Skip to content

Commit e59a7e0

Browse files
Merge branch 'raktima-opensignlabs-patch-10' of https://github.com/OpenSignLabs/OpenSign into raktima-opensignlabs-patch-10
2 parents 1d6655e + 09b39a4 commit e59a7e0

File tree

8 files changed

+124
-139
lines changed

8 files changed

+124
-139
lines changed

apps/OpenSign/src/components/RenderDebugPdf.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ const RenderDebugPdf = (props) => {
1313
>
1414
<Document
1515
onLoadError={() => {
16-
const load = {
17-
status: false,
18-
type: "failed"
19-
};
20-
props.setPdfLoadFail(load);
16+
props.setPdfLoadFail(false);
2117
}}
2218
loading={"Loading Document.."}
2319
onLoadSuccess={props.pageDetails}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function Placeholder(props) {
9191
const [placeholderBorder, setPlaceholderBorder] = useState({ w: 0, h: 0 });
9292
const [isDraggingEnabled, setDraggingEnabled] = useState(true);
9393
const [isShowDateFormat, setIsShowDateFormat] = useState(false);
94+
const [containerScale, setContainerScale] = useState();
9495
const [selectDate, setSelectDate] = useState({
9596
date:
9697
props.pos.type === "date"
@@ -120,7 +121,14 @@ function Placeholder(props) {
120121
width: null,
121122
height: null
122123
});
123-
const containerScale = props.containerWH.width / props.pdfOriginalWH.width;
124+
125+
useEffect(() => {
126+
const getPdfPageWidth = props.pdfOriginalWH.find(
127+
(data) => data.pageNumber === props.pageNumber
128+
);
129+
setContainerScale(props.containerWH.width / getPdfPageWidth.width);
130+
// eslint-disable-next-line react-hooks/exhaustive-deps
131+
}, [props.containerWH.width, props.pdfOriginalWH]);
124132
const dateFormatArr = [
125133
"L",
126134
"DD-MM-YYYY",
@@ -558,7 +566,10 @@ function Placeholder(props) {
558566
);
559567
};
560568
const xPos = (pos, signYourself) => {
561-
const containerScale = props.containerWH.width / props.pdfOriginalWH.width;
569+
const getPdfPageWidth = props.pdfOriginalWH.find(
570+
(data) => data.pageNumber === props.pageNumber
571+
);
572+
const containerScale = props.containerWH.width / getPdfPageWidth?.width;
562573
const resizePos = pos.xPosition;
563574
if (signYourself) {
564575
return resizePos * containerScale * props.scale;
@@ -580,7 +591,10 @@ function Placeholder(props) {
580591
}
581592
};
582593
const yPos = (pos, signYourself) => {
583-
const containerScale = props.containerWH.width / props.pdfOriginalWH.width;
594+
const getPdfPageWidth = props.pdfOriginalWH.find(
595+
(data) => data.pageNumber === props.pageNumber
596+
);
597+
const containerScale = props.containerWH.width / getPdfPageWidth.width;
584598
const resizePos = pos.yPosition;
585599

586600
if (signYourself) {

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React from "react";
22
import RSC from "react-scrollbars-custom";
33
import { Document, Page } from "react-pdf";
44
import {
@@ -28,7 +28,8 @@ function RenderPdf({
2828
pdfRequest,
2929
signerObjectId,
3030
signedSigners,
31-
setPdfLoadFail,
31+
pdfLoad,
32+
setPdfLoad,
3233
placeholder,
3334
setSignerPos,
3435
setXyPostion,
@@ -55,19 +56,19 @@ function RenderPdf({
5556
handleTextSettingModal,
5657
setTempSignerId,
5758
uniqueId,
58-
setPdfRenderHeight,
5959
pdfOriginalWH,
6060
scale
6161
}) {
62-
const [isLoadPdf, setIsLoadPdf] = useState(false);
63-
6462
const isMobile = window.innerWidth < 767;
6563
//check isGuestSigner is present in local if yes than handle login flow header in mobile view
6664
const isGuestSigner = localStorage.getItem("isGuestSigner");
6765

6866
// handle signature block width and height according to screen
6967
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;
7172
const defaultWidth = defaultWidthHeight(pos.type).width;
7273
const posWidth = pos.Width ? pos.Width : defaultWidth;
7374
if (signYourself) {
@@ -93,7 +94,10 @@ function RenderPdf({
9394
}
9495
};
9596
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;
97101

98102
const posHeight = pos.Height || defaultWidthHeight(pos.type).height;
99103
if (signYourself) {
@@ -189,6 +193,7 @@ function RenderPdf({
189193
scale={scale}
190194
containerWH={containerWH}
191195
pdfOriginalWH={pdfOriginalWH}
196+
pageNumber={pageNumber}
192197
/>
193198
</React.Fragment>
194199
)
@@ -248,9 +253,8 @@ function RenderPdf({
248253
ref={drop}
249254
id="container"
250255
>
251-
{isLoadPdf &&
252-
containerWH?.width &&
253-
pdfOriginalWH?.width &&
256+
{containerWH?.width &&
257+
pdfOriginalWH.length > 0 &&
254258
(pdfRequest
255259
? signerPos.map((data, key) => {
256260
return (
@@ -315,6 +319,7 @@ function RenderPdf({
315319
scale={scale}
316320
containerWH={containerWH}
317321
pdfOriginalWH={pdfOriginalWH}
322+
pageNumber={pageNumber}
318323
/>
319324
</React.Fragment>
320325
);
@@ -367,6 +372,7 @@ function RenderPdf({
367372
}
368373
scale={scale}
369374
pdfOriginalWH={pdfOriginalWH}
375+
pageNumber={pageNumber}
370376
/>
371377
)
372378
);
@@ -379,7 +385,7 @@ function RenderPdf({
379385
<div className="flex items-center justify-center">
380386
<Document
381387
onLoadError={() => {
382-
setPdfLoadFail(true);
388+
setPdfLoad(false);
383389
}}
384390
loading={"Loading Document.."}
385391
onLoadSuccess={pageDetails}
@@ -398,10 +404,6 @@ function RenderPdf({
398404
}
399405
>
400406
<Page
401-
onLoadSuccess={({ height }) => {
402-
setPdfRenderHeight && setPdfRenderHeight(height);
403-
setIsLoadPdf(true);
404-
}}
405407
key={index}
406408
pageNumber={pageNumber}
407409
width={containerWH.width}
@@ -432,9 +434,9 @@ function RenderPdf({
432434
ref={drop}
433435
id="container"
434436
>
435-
{isLoadPdf &&
437+
{pdfLoad &&
436438
containerWH?.width &&
437-
pdfOriginalWH?.width &&
439+
pdfOriginalWH.length > 0 &&
438440
(pdfRequest //pdf request sign flow
439441
? signerPos?.map((data, key) => {
440442
return (
@@ -499,6 +501,7 @@ function RenderPdf({
499501
scale={scale}
500502
containerWH={containerWH}
501503
pdfOriginalWH={pdfOriginalWH}
504+
pageNumber={pageNumber}
502505
/>
503506
</React.Fragment>
504507
);
@@ -556,6 +559,7 @@ function RenderPdf({
556559
scale={scale}
557560
containerWH={containerWH}
558561
pdfOriginalWH={pdfOriginalWH}
562+
pageNumber={pageNumber}
559563
/>
560564
</React.Fragment>
561565
);
@@ -567,11 +571,7 @@ function RenderPdf({
567571
{/* this component for render pdf document is in middle of the component */}
568572
<Document
569573
onLoadError={() => {
570-
const load = {
571-
status: false,
572-
type: "failed"
573-
};
574-
setPdfLoadFail(load);
574+
pdfLoad(false);
575575
}}
576576
loading={"Loading Document.."}
577577
onLoadSuccess={pageDetails}
@@ -590,10 +590,6 @@ function RenderPdf({
590590
}
591591
>
592592
<Page
593-
onLoadSuccess={({ height }) => {
594-
setPdfRenderHeight && setPdfRenderHeight(height);
595-
setIsLoadPdf(true);
596-
}}
597593
key={index}
598594
width={containerWH.width}
599595
scale={scale || 1}

apps/OpenSign/src/constant/Utils.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,6 @@ export const changeImageWH = async (base64Image) => {
12261226
export const multiSignEmbed = async (
12271227
xyPositionArray,
12281228
pdfDoc,
1229-
pdfOriginalWH,
12301229
signyourself,
12311230
scale
12321231
) => {
@@ -1287,20 +1286,8 @@ export const multiSignEmbed = async (
12871286
}
12881287
}
12891288
let widgetWidth, widgetHeight;
1290-
widgetWidth = placeholderWidth(
1291-
position,
1292-
scale,
1293-
signyourself,
1294-
pdfOriginalWH,
1295-
scale
1296-
);
1297-
widgetHeight = placeholderHeight(
1298-
position,
1299-
scale,
1300-
signyourself,
1301-
pdfOriginalWH.height,
1302-
scale
1303-
);
1289+
widgetWidth = placeholderWidth(position);
1290+
widgetHeight = placeholderHeight(position);
13041291
const xPos = (position) => {
13051292
const resizePos = position.xPosition;
13061293
//first two condition handle to old data already saved from mobile view which scale point diffrent

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function PdfRequestFiles() {
8686
const [defaultSignImg, setDefaultSignImg] = useState();
8787
const [isDocId, setIsDocId] = useState(false);
8888
const [pdfNewWidth, setPdfNewWidth] = useState();
89-
const [pdfOriginalWH, setPdfOriginalWH] = useState();
89+
const [pdfOriginalWH, setPdfOriginalWH] = useState([]);
9090
const [signerPos, setSignerPos] = useState([]);
9191
const [signerObjectId, setSignerObjectId] = useState();
9292
const [isUiLoading, setIsUiLoading] = useState(false);
@@ -110,10 +110,7 @@ function PdfRequestFiles() {
110110
});
111111
const [myInitial, setMyInitial] = useState("");
112112
const [isInitial, setIsInitial] = useState(false);
113-
const [pdfLoadFail, setPdfLoadFail] = useState({
114-
status: false,
115-
type: "load"
116-
});
113+
const [pdfLoad, setPdfLoad] = useState(false);
117114
const [isSigned, setIsSigned] = useState(false);
118115
const [isExpired, setIsExpired] = useState(false);
119116
const [alreadySign, setAlreadySign] = useState(false);
@@ -129,7 +126,6 @@ function PdfRequestFiles() {
129126
const [isVerifyModal, setIsVerifyModal] = useState(false);
130127
const [otp, setOtp] = useState("");
131128
const [contractName, setContractName] = useState("");
132-
const [pdfRenderHeight, setPdfRenderHeight] = useState();
133129
const [zoomPercent, setZoomPercent] = useState(0);
134130
const [totalZoomPercent, setTotalZoomPercent] = useState();
135131
const [scale, setScale] = useState(1);
@@ -785,7 +781,6 @@ function PdfRequestFiles() {
785781
const pdfBytes = await multiSignEmbed(
786782
pngUrl,
787783
pdfDoc,
788-
pdfOriginalWH,
789784
isSignYourSelfFlow,
790785
scale
791786
);
@@ -1020,14 +1015,16 @@ function PdfRequestFiles() {
10201015
];
10211016
//function for get pdf page details
10221017
const pageDetails = async (pdf) => {
1023-
const firstPage = await pdf.getPage(1);
1024-
const scale = 1;
1025-
const { width, height } = firstPage.getViewport({ scale });
1026-
// console.log("width height", width, height);
1027-
setPdfOriginalWH({ width: width, height: height });
1028-
setPdfLoadFail({
1029-
status: true
1030-
});
1018+
let pdfWHObj = [];
1019+
const totalPages = pdf.numPages; // Get the total number of pages
1020+
for (let index = 0; index < totalPages; index++) {
1021+
const getPage = await pdf.getPage(index + 1);
1022+
const scale = 1;
1023+
const { width, height } = getPage.getViewport({ scale });
1024+
pdfWHObj.push({ pageNumber: index + 1, width, height });
1025+
}
1026+
setPdfOriginalWH(pdfWHObj);
1027+
setPdfLoad(true);
10311028
};
10321029
//function for change page
10331030
function changePage(offset) {
@@ -1555,7 +1552,6 @@ function PdfRequestFiles() {
15551552
<PdfZoom
15561553
setScale={setScale}
15571554
scale={scale}
1558-
pdfOriginalWH={pdfOriginalWH}
15591555
containerWH={containerWH}
15601556
setZoomPercent={setZoomPercent}
15611557
zoomPercent={zoomPercent}
@@ -1732,8 +1728,8 @@ function PdfRequestFiles() {
17321728
pdfRequest={true}
17331729
signerObjectId={signerObjectId}
17341730
signedSigners={signedSigners}
1735-
setPdfLoadFail={setPdfLoadFail}
1736-
pdfLoadFail={pdfLoadFail}
1731+
setPdfLoad={setPdfLoad}
1732+
pdfLoad={pdfLoad}
17371733
setSignerPos={setSignerPos}
17381734
containerWH={containerWH}
17391735
setIsInitial={setIsInitial}
@@ -1743,8 +1739,6 @@ function PdfRequestFiles() {
17431739
selectWidgetId={selectWidgetId}
17441740
setCurrWidgetsDetails={setCurrWidgetsDetails}
17451741
divRef={divRef}
1746-
setPdfRenderHeight={setPdfRenderHeight}
1747-
pdfRenderHeight={pdfRenderHeight}
17481742
setIsResize={setIsResize}
17491743
isResize={isResize}
17501744
setTotalZoomPercent={setTotalZoomPercent}

0 commit comments

Comments
 (0)