Skip to content

Commit c422b11

Browse files
fix: text widget font size issue in large pdf
1 parent 95d2794 commit c422b11

File tree

9 files changed

+104
-67
lines changed

9 files changed

+104
-67
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PlaceholderBorder from "./PlaceholderBorder";
44
import { Rnd } from "react-rnd";
55
import {
66
defaultWidthHeight,
7+
getContainerScale,
78
handleCopyNextToWidget,
89
isTabAndMobile,
910
onChangeInput,
@@ -634,10 +635,11 @@ function Placeholder(props) {
634635
);
635636
};
636637
const xPos = (pos, signYourself) => {
637-
const getPdfPageWidth = props.pdfOriginalWH.find(
638-
(data) => data.pageNumber === props.pageNumber
638+
const containerScale = getContainerScale(
639+
props.pdfOriginalWH,
640+
props.pageNumber,
641+
props.containerWH
639642
);
640-
const containerScale = props.containerWH.width / getPdfPageWidth?.width;
641643
const resizePos = pos.xPosition;
642644
if (signYourself) {
643645
return resizePos * containerScale * props.scale;
@@ -659,10 +661,11 @@ function Placeholder(props) {
659661
}
660662
};
661663
const yPos = (pos, signYourself) => {
662-
const getPdfPageWidth = props.pdfOriginalWH.find(
663-
(data) => data.pageNumber === props.pageNumber
664+
const containerScale = getContainerScale(
665+
props.pdfOriginalWH,
666+
props.pageNumber,
667+
props.containerWH
664668
);
665-
const containerScale = props.containerWH.width / getPdfPageWidth.width;
666669
const resizePos = pos.yPosition;
667670

668671
if (signYourself) {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ function PlaceholderBorder(props) {
4747
onTouchEnd={() =>
4848
props.pos.type === textWidget && props?.setDraggingEnabled(true)
4949
}
50-
className="absolute inline-block w-[14px] h-[14px] hover:cursor-sw-resize"
50+
className="absolute inline-block w-[14px] h-[14px] border-[0.2px] overflow-hidden border-dashed"
5151
style={{
5252
borderColor: themeColor,
53-
borderStyle: "dashed",
5453
minWidth: handleMinWidth() || 0,
55-
minHeight: handleMinHeight() || 0,
56-
borderWidth: "0.2px",
57-
overflow: "hidden"
54+
minHeight: handleMinHeight() || 0
5855
}}
5956
></div>
6057
);

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ function PlaceholderType(props) {
139139

140140
const ExampleCustomInput = forwardRef(({ value, onClick }, ref) => (
141141
<div
142-
className={`${selectWidgetCls} overflow-hidden`}
143-
style={{ fontSize: calculateFontSize() }}
142+
className={`${selectWidgetCls} text-[12px] overflow-hidden`}
144143
onClick={onClick}
145144
ref={ref}
146145
>
@@ -171,12 +170,6 @@ function PlaceholderType(props) {
171170
}
172171
// eslint-disable-next-line react-hooks/exhaustive-deps
173172
}, [type]);
174-
175-
const calculateFontSize = () => {
176-
const fontSize = 10 + Math.min(props.pos.Width, props.pos.Height) * 0.1;
177-
const size = fontSize ? fontSize : 12;
178-
return size + "px";
179-
};
180173
//function for show checked checkbox
181174
const selectCheckbox = (ind) => {
182175
const res = props.pos.options?.response;
@@ -426,7 +419,8 @@ function PlaceholderType(props) {
426419
fontSize: props.pos.options?.fontSize
427420
? props.pos.options?.fontSize + "px"
428421
: "12px",
429-
color: props.pos.options?.fontColor || "black"
422+
color: props.pos.options?.fontColor || "black",
423+
overflow: "hidden"
430424
}}
431425
>
432426
<span>{type}</span>
@@ -465,10 +459,7 @@ function PlaceholderType(props) {
465459
})}
466460
</select>
467461
) : (
468-
<div
469-
className={selectWidgetCls}
470-
style={{ fontSize: calculateFontSize() }}
471-
>
462+
<div className="text-[12px] overflow-hidden">
472463
{props.pos?.options?.name ? props.pos.options.name : type}
473464
</div>
474465
);
@@ -527,7 +518,8 @@ function PlaceholderType(props) {
527518
fontSize: props.pos.options?.fontSize
528519
? props.pos.options?.fontSize + "px"
529520
: "12px",
530-
color: props.pos.options?.fontColor || "black"
521+
color: props.pos.options?.fontColor || "black",
522+
fontFamily: "Arial, sans-serif"
531523
}}
532524
>
533525
<span>{type}</span>
@@ -569,7 +561,9 @@ function PlaceholderType(props) {
569561
fontSize: props.pos.options?.fontSize
570562
? props.pos.options?.fontSize + "px"
571563
: "12px",
572-
color: props.pos.options?.fontColor || "black"
564+
color: props.pos.options?.fontColor || "black",
565+
overflow: "hidden",
566+
fontFamily: "Arial, sans-serif"
573567
}}
574568
>
575569
<span>{type}</span>
@@ -611,7 +605,8 @@ function PlaceholderType(props) {
611605
fontSize: props.pos.options?.fontSize
612606
? props.pos.options?.fontSize + "px"
613607
: "12px",
614-
color: props.pos.options?.fontColor || "black"
608+
color: props.pos.options?.fontColor || "black",
609+
fontFamily: "Arial, sans-serif"
615610
}}
616611
>
617612
<span>{type}</span>
@@ -677,7 +672,7 @@ function PlaceholderType(props) {
677672
/>
678673
</div>
679674
) : (
680-
<div className="text-[12px] text-black uppercase items-center">
675+
<div className="text-[12px] text-black items-center overflow-hidden">
681676
<span>
682677
{props.selectDate
683678
? props.selectDate?.format
@@ -732,7 +727,8 @@ function PlaceholderType(props) {
732727
fontSize: props.pos.options?.fontSize
733728
? props.pos.options?.fontSize + "px"
734729
: "12px",
735-
color: props.pos.options?.fontColor || "black"
730+
color: props.pos.options?.fontColor || "black",
731+
fontFamily: "Arial, sans-serif"
736732
}}
737733
cols="50"
738734
/>
@@ -742,7 +738,8 @@ function PlaceholderType(props) {
742738
fontSize: props.pos.options?.fontSize
743739
? props.pos.options?.fontSize + "px"
744740
: "12px",
745-
color: props.pos.options?.fontColor || "black"
741+
color: props.pos.options?.fontColor || "black",
742+
fontFamily: "Arial, sans-serif"
746743
}}
747744
>
748745
<span>{type}</span>
@@ -801,6 +798,7 @@ function PlaceholderType(props) {
801798
}}
802799
className={textWidgetCls}
803800
style={{
801+
fontFamily: "Arial, sans-serif",
804802
fontSize: props.pos.options?.fontSize
805803
? props.pos.options?.fontSize + "px"
806804
: "12px",

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RSC from "react-scrollbars-custom";
33
import { Document, Page } from "react-pdf";
44
import {
55
defaultWidthHeight,
6+
getContainerScale,
67
handleImageResize,
78
handleSignYourselfImageResize
89
} from "../../constant/Utils";
@@ -68,10 +69,11 @@ function RenderPdf({
6869

6970
// handle signature block width and height according to screen
7071
const posWidth = (pos, signYourself) => {
71-
const getPdfPageWidth = pdfOriginalWH.find(
72-
(data) => data.pageNumber === pageNumber
72+
const containerScale = getContainerScale(
73+
pdfOriginalWH,
74+
pageNumber,
75+
containerWH
7376
);
74-
const containerScale = containerWH.width / getPdfPageWidth.width || 1;
7577
const defaultWidth = defaultWidthHeight(pos.type).width;
7678
const posWidth = pos.Width ? pos.Width : defaultWidth;
7779
if (signYourself) {
@@ -97,11 +99,11 @@ function RenderPdf({
9799
}
98100
};
99101
const posHeight = (pos, signYourself) => {
100-
const getPdfPageWidth = pdfOriginalWH.find(
101-
(data) => data.pageNumber === pageNumber
102+
const containerScale = getContainerScale(
103+
pdfOriginalWH,
104+
pageNumber,
105+
containerWH
102106
);
103-
const containerScale = containerWH.width / getPdfPageWidth?.width || 1;
104-
105107
const posHeight = pos.Height || defaultWidthHeight(pos.type).height;
106108
if (signYourself) {
107109
return posHeight * scale * containerScale;

apps/OpenSign/src/constant/Utils.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,8 @@ export const multiSignEmbed = async (
12541254
xyPositionArray,
12551255
pdfDoc,
12561256
signyourself,
1257-
scale
1257+
scale,
1258+
containerScale
12581259
) => {
12591260
for (let item of xyPositionArray) {
12601261
const typeExist = item.pos.some((data) => data?.type);
@@ -1416,7 +1417,9 @@ export const multiSignEmbed = async (
14161417
}
14171418
} else if (widgetTypeExist) {
14181419
const font = await pdfDoc.embedFont("Helvetica");
1419-
const fontSize = parseInt(position?.options?.fontSize) || 12;
1420+
const fontSize =
1421+
parseInt(position?.options?.fontSize / containerScale) ||
1422+
12 / containerScale;
14201423
const color = position?.options?.fontColor;
14211424
let updateColorInRgb;
14221425
if (color === "red") {
@@ -1591,7 +1594,7 @@ export const multiSignEmbed = async (
15911594
});
15921595
}
15931596
const pdfBytes = await pdfDoc.saveAsBase64({ useObjectStreams: false });
1594-
// console.log("pdf", pdfBytes);
1597+
//console.log("pdf", pdfBytes);
15951598
return pdfBytes;
15961599
};
15971600

@@ -2211,3 +2214,11 @@ function getImagePosition(page, image, sizeRatio) {
22112214
rotate: page.getRotation()
22122215
};
22132216
}
2217+
//function to use calculate pdf rendering scale in the container
2218+
export const getContainerScale = (pdfOriginalWH, pageNumber, containerWH) => {
2219+
const getPdfPageWidth = pdfOriginalWH.find(
2220+
(data) => data.pageNumber === pageNumber
2221+
);
2222+
const containerScale = containerWH?.width / getPdfPageWidth?.width || 1;
2223+
return containerScale;
2224+
};

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
contactBook,
3131
handleDownloadPdf,
3232
handleToPrint,
33-
handleDownloadCertificate
33+
handleDownloadCertificate,
34+
getContainerScale
3435
} from "../constant/Utils";
3536
import LoaderWithMsg from "../primitives/LoaderWithMsg";
3637
import HandleError from "../primitives/HandleError";
@@ -857,12 +858,18 @@ function PdfRequestFiles(props) {
857858
await embedDocId(pdfDoc, documentId, allPages);
858859
}
859860
}
861+
const containerScale = getContainerScale(
862+
pdfOriginalWH,
863+
pageNumber,
864+
containerWH
865+
);
860866
//embed multi signature in pdf
861867
const pdfBytes = await multiSignEmbed(
862868
pngUrl,
863869
pdfDoc,
864870
isSignYourSelfFlow,
865-
scale
871+
scale,
872+
containerScale
866873
);
867874
// console.log("pdfte", pdfBytes);
868875
//get ExistUserPtr object id of user class to get tenantDetails

apps/OpenSign/src/pages/PlaceHolderSign.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {
3333
replaceMailVaribles,
3434
copytoData,
3535
fetchSubscription,
36-
convertPdfArrayBuffer
36+
convertPdfArrayBuffer,
37+
getContainerScale
3738
} from "../constant/Utils";
3839
import RenderPdf from "../components/pdf/RenderPdf";
3940
import { useNavigate } from "react-router-dom";
@@ -452,10 +453,11 @@ function PlaceHolderSign() {
452453
setZIndex(posZIndex);
453454
const signer = signersdata.find((x) => x.Id === uniqueId);
454455
const key = randomId();
455-
const getPdfPageWidth = pdfOriginalWH.find(
456-
(data) => data.pageNumber === pageNumber
456+
const containerScale = getContainerScale(
457+
pdfOriginalWH,
458+
pageNumber,
459+
containerWH
457460
);
458-
const containerScale = containerWH?.width / getPdfPageWidth?.width || 1;
459461
let dropData = [];
460462
let placeHolder;
461463
const dragTypeValue = item?.text ? item.text : monitor.type;
@@ -676,11 +678,11 @@ function PlaceHolderSign() {
676678
updateSignPos.splice(0, updateSignPos.length, ...dataNewPlace);
677679
const signId = signerId ? signerId : uniqueId; //? signerId : signerObjId;
678680
const keyValue = key ? key : dragKey;
679-
const getPdfPageWidth = pdfOriginalWH.find(
680-
(data) => data.pageNumber === pageNumber
681+
const containerScale = getContainerScale(
682+
pdfOriginalWH,
683+
pageNumber,
684+
containerWH
681685
);
682-
const containerScale = containerWH.width / getPdfPageWidth?.width;
683-
684686
if (keyValue >= 0) {
685687
let filterSignerPos;
686688
if (signId) {
@@ -851,14 +853,19 @@ function PlaceHolderSign() {
851853
const pdfDoc = await PDFDocument.load(existingPdfBytes, {
852854
ignoreEncryption: true
853855
});
854-
855856
const isSignYourSelfFlow = false;
857+
const containerScale = getContainerScale(
858+
pdfOriginalWH,
859+
pageNumber,
860+
containerWH
861+
);
856862
try {
857863
const pdfBytes = await multiSignEmbed(
858864
placeholder,
859865
pdfDoc,
860866
isSignYourSelfFlow,
861-
containerWH
867+
containerWH,
868+
containerScale
862869
);
863870

864871
const fileName = sanitizeFileName(pdfDetails[0].Name) + ".pdf";

0 commit comments

Comments
 (0)