Skip to content

Commit e4f0e9c

Browse files
Merge branch 'raktima-opensignlabs-patch-10' of https://github.com/OpenSignLabs/OpenSign into raktima-opensignlabs-patch-10
2 parents 12599c1 + 6bb3203 commit e4f0e9c

File tree

6 files changed

+193
-61
lines changed

6 files changed

+193
-61
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ function Placeholder(props) {
565565
const xPos = (pos, signYourself) => {
566566
const containerScale = props.containerWH.width / props.pdfOriginalWH.width;
567567
const resizePos = pos.xPosition;
568+
console.log("go here", resizePos, containerScale, props.scale);
568569
if (signYourself) {
569570
return resizePos * containerScale * props.scale;
570571
} else {
@@ -582,6 +583,7 @@ function Placeholder(props) {
582583
// return resizePos * pos.scale * containerScale * props.scale;
583584
// }
584585
// }
586+
console.log("go here", resizePos, containerScale, props.scale);
585587
return resizePos * containerScale * props.scale;
586588
}
587589
};

apps/OpenSign/src/constant/Utils.js

Lines changed: 145 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ export const multiSignEmbed = async (
12481248
const newWidth = containerWH.width;
12491249
const scale = newWidth / pdfOriginalWH.width;
12501250
const pageNo = item.pageNumber;
1251+
console.log("page number", pageNo);
12511252
const imgUrlList = updateItem;
12521253
const pages = pdfDoc.getPages();
12531254
const form = pdfDoc.getForm();
@@ -1261,10 +1262,6 @@ export const multiSignEmbed = async (
12611262
const newUrl = await convertPNGtoJPEG(signUrl);
12621263
signUrl = newUrl;
12631264
}
1264-
// const checkUrl = urlValidator(signUrl);
1265-
// if (checkUrl) {
1266-
// signUrl = signUrl + "?get";
1267-
// }
12681265
const res = await fetch(signUrl);
12691266
return res.arrayBuffer();
12701267
}
@@ -1480,21 +1477,23 @@ export const multiSignEmbed = async (
14801477
? breakTextIntoLines(textContent, fixedWidth)
14811478
: NewbreakTextIntoLines(textContent, fixedWidth);
14821479
// Set initial y-coordinate for the first line
1483-
const labelDefaultHeight = defaultWidthHeight(position.type).height;
1484-
1485-
let y = yPos(position, null, labelDefaultHeight);
14861480
let x = xPos(position);
1487-
//xPos(position)
1481+
let y = position.yPosition;
14881482
// Embed each line on the page
14891483
for (const line of lines) {
1490-
page.drawText(line, {
1491-
x: x,
1484+
const correction = compensateRotation(
1485+
page.getRotation().angle,
1486+
x,
14921487
y,
1488+
1,
1489+
page.getSize(),
1490+
fontSize,
1491+
updateColorInRgb,
14931492
font,
1494-
color: updateColorInRgb,
1495-
size: fontSize
1496-
});
1497-
y -= 18; // Adjust the line height as needed
1493+
page
1494+
);
1495+
page.drawText(line, correction);
1496+
y += 18; // Adjust the line height as needed
14981497
}
14991498
} else if (position.type === "dropdown") {
15001499
const dropdownRandomId = "dropdown" + randomId();
@@ -1506,13 +1505,23 @@ export const multiSignEmbed = async (
15061505
dropdown.select(position?.options?.defaultValue);
15071506
}
15081507

1509-
dropdown.addToPage(page, {
1510-
x: xPos(position),
1511-
y: yPos(position),
1508+
// dropdown.addToPage(page, {
1509+
// x: xPos(position),
1510+
// y: yPos(position),
1511+
// width: scaleWidth,
1512+
// height: scaleHeight,
1513+
// borderWidth: 0
1514+
// });
1515+
const dropdownObj = {
1516+
x: position.xPosition,
1517+
y: position.yPosition,
15121518
width: scaleWidth,
1513-
height: scaleHeight,
1514-
borderWidth: 0
1515-
});
1519+
height: scaleHeight
1520+
};
1521+
1522+
const dropdownOption = getImagePosition(page, dropdownObj, 1);
1523+
// page.drawImage(img, imageOptions);
1524+
dropdown.addToPage(page, dropdownOption);
15161525
dropdown.enableReadOnly();
15171526
} else if (position.type === radioButtonWidget) {
15181527
const radioRandomId = "radio" + randomId();
@@ -1535,7 +1544,37 @@ export const multiSignEmbed = async (
15351544
y: yPosition + 2,
15361545
size: 11
15371546
});
1547+
// const text = {
1548+
// x: position.xPosition + 15,
1549+
// y: position.yPosition + 2,
1550+
// size: 11
1551+
// };
1552+
// const correction = compensateRotationRadioFont(
1553+
// page.getRotation().angle,
1554+
// position.xPosition,
1555+
// position.yPosition,
1556+
// 1,
1557+
// page.getSize(),
1558+
// 11,
1559+
// addYPosition,
1560+
// i
1561+
// );
1562+
1563+
// // const imageOptions = getImagePosition(page, text, 1);
1564+
// console.log("correction", correction);
1565+
1566+
// page.drawText(data, correction);
15381567
}
1568+
// const radio = {
1569+
// x: position.xPosition,
1570+
// y: position.yPosition,
1571+
// width: 11,
1572+
// height: 11
1573+
// };
1574+
1575+
// const imageOptions = getImagePosition(page, radio, 1);
1576+
// console.log("imageOptions", imageOptions);
1577+
// radioGroup.addOptionToPage(data, page, imageOptions);
15391578
radioGroup.addOptionToPage(data, page, {
15401579
x: xPos(position),
15411580
y: yPosition,
@@ -1560,12 +1599,14 @@ export const multiSignEmbed = async (
15601599
width: scaleWidth,
15611600
height: scaleHeight
15621601
};
1602+
15631603
const imageOptions = getImagePosition(page, signature, 1);
15641604
page.drawImage(img, imageOptions);
15651605
}
15661606
});
15671607
}
15681608
const pdfBytes = await pdfDoc.saveAsBase64({ useObjectStreams: false });
1609+
// console.log("pdf", pdfBytes);
15691610
return pdfBytes;
15701611
};
15711612

@@ -2077,8 +2118,76 @@ export async function findContact(value) {
20772118
}
20782119

20792120
// `compensateRotation` is used to calculate x and y position of widget on portait, landscape pdf for pdf-lib
2080-
function compensateRotation(pageRotation, x, y, scale, dimensions, fontSize) {
2081-
//fontsize = imagewidth
2121+
// function compensateRotationRadioFont(
2122+
// pageRotation,
2123+
// x,
2124+
// y,
2125+
// scale,
2126+
// dimensions,
2127+
// fontSize,
2128+
// addYPosition,
2129+
// i
2130+
// ) {
2131+
// //fontsize = imagewidth
2132+
// let rotationRads = (pageRotation * Math.PI) / 180;
2133+
2134+
// //These coords are now from bottom/left
2135+
// let coordsFromBottomLeft = { x: x / scale };
2136+
// if (pageRotation === 90 || pageRotation === 270) {
2137+
// coordsFromBottomLeft.y = dimensions.width - (y + fontSize) / scale;
2138+
// if (i > 1) {
2139+
// coordsFromBottomLeft.y = coordsFromBottomLeft.y - addYPosition;
2140+
// }
2141+
// } else {
2142+
// coordsFromBottomLeft.y = dimensions.height - (y + fontSize) / scale;
2143+
// }
2144+
2145+
// let drawX = null;
2146+
// let drawY = null;
2147+
// if (pageRotation === 90) {
2148+
// drawX =
2149+
// coordsFromBottomLeft.x * Math.cos(rotationRads) -
2150+
// coordsFromBottomLeft.y * Math.sin(rotationRads) +
2151+
// dimensions.width;
2152+
// drawY =
2153+
// coordsFromBottomLeft.x * Math.sin(rotationRads) +
2154+
// coordsFromBottomLeft.y * Math.cos(rotationRads);
2155+
// } else if (pageRotation === 180) {
2156+
// drawX =
2157+
// coordsFromBottomLeft.x * Math.cos(rotationRads) -
2158+
// coordsFromBottomLeft.y * Math.sin(rotationRads) +
2159+
// dimensions.width;
2160+
// drawY =
2161+
// coordsFromBottomLeft.x * Math.sin(rotationRads) +
2162+
// coordsFromBottomLeft.y * Math.cos(rotationRads) +
2163+
// dimensions.height;
2164+
// } else if (pageRotation === 270) {
2165+
// drawX =
2166+
// coordsFromBottomLeft.x * Math.cos(rotationRads) -
2167+
// coordsFromBottomLeft.y * Math.sin(rotationRads);
2168+
// drawY =
2169+
// coordsFromBottomLeft.x * Math.sin(rotationRads) +
2170+
// coordsFromBottomLeft.y * Math.cos(rotationRads) +
2171+
// dimensions.height;
2172+
// } else {
2173+
// //no rotation
2174+
// drawX = coordsFromBottomLeft.x;
2175+
// drawY = coordsFromBottomLeft.y;
2176+
// }
2177+
// return { x: drawX + 15, y: drawY + 2, size: fontSize };
2178+
// }
2179+
// `compensateRotation` is used to calculate x and y position of widget on portait, landscape pdf for pdf-lib
2180+
function compensateRotation(
2181+
pageRotation,
2182+
x,
2183+
y,
2184+
scale,
2185+
dimensions,
2186+
fontSize,
2187+
updateColorInRgb,
2188+
font,
2189+
page
2190+
) {
20822191
let rotationRads = (pageRotation * Math.PI) / 180;
20832192

20842193
//These coords are now from bottom/left
@@ -2121,17 +2230,30 @@ function compensateRotation(pageRotation, x, y, scale, dimensions, fontSize) {
21212230
drawX = coordsFromBottomLeft.x;
21222231
drawY = coordsFromBottomLeft.y;
21232232
}
2124-
return { x: drawX, y: drawY };
2233+
if (font) {
2234+
return {
2235+
x: drawX,
2236+
y: drawY,
2237+
font,
2238+
color: updateColorInRgb,
2239+
size: fontSize,
2240+
rotate: page.getRotation()
2241+
};
2242+
} else {
2243+
return { x: drawX, y: drawY };
2244+
}
21252245
}
21262246

21272247
// `getImagePosition` is used to calulcate position of image type widget like x, y, width, height for pdf-lib
21282248
function getImagePosition(page, image, sizeRatio) {
21292249
let pageWidth;
21302250
// pageHeight;
21312251
if ([90, 270].includes(page.getRotation().angle)) {
2252+
console.log("go in 90 degree");
21322253
pageWidth = page.getHeight();
21332254
// pageHeight = page.getWidth();
21342255
} else {
2256+
console.log("go in 180 degree");
21352257
pageWidth = page.getWidth();
21362258
// pageHeight = page.getHeight();
21372259
}

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,15 +1022,13 @@ function PdfRequestFiles() {
10221022

10231023
//function for get pdf page details
10241024
const pageDetails = async (pdf) => {
1025-
pdf.getPage(1).then((pdfPage) => {
1026-
const pageWidth = pdfPage.view[2];
1027-
const pageHeight = pdfPage.view[3];
1028-
setPdfOriginalWH({ width: pageWidth, height: pageHeight });
1029-
1030-
const load = {
1031-
status: true
1032-
};
1033-
setPdfLoadFail(load);
1025+
const firstPage = await pdf.getPage(1);
1026+
const scale = 1;
1027+
const { width, height } = firstPage.getViewport({ scale });
1028+
// console.log("width height", width, height);
1029+
setPdfOriginalWH({ width: width, height: height });
1030+
setPdfLoadFail({
1031+
status: true
10341032
});
10351033
};
10361034
//function for change page
@@ -1241,6 +1239,7 @@ function PdfRequestFiles() {
12411239
const handleDontShow = (isChecked) => {
12421240
setIsDontShow(isChecked);
12431241
};
1242+
// console.log("signerpos", signerPos);
12441243
//function to close tour and save tour status
12451244
const closeRequestSignTour = async () => {
12461245
setRequestSignTour(true);

apps/OpenSign/src/pages/PlaceHolderSign.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function PlaceHolderSign() {
458458
const addPositionOfSignature = (item, monitor) => {
459459
getSignerPos(item, monitor);
460460
};
461-
461+
// console.log("signerpos", signerPos);
462462
const getSignerPos = (item, monitor) => {
463463
// setSignerObjId("");
464464
// setContractName("");
@@ -467,12 +467,18 @@ function PlaceHolderSign() {
467467
setZIndex(posZIndex);
468468
const signer = signersdata.find((x) => x.Id === uniqueId);
469469
const key = randomId();
470-
const containerScale = containerWH.width / pdfOriginalWH.width;
470+
const containerScale = containerWH?.width / pdfOriginalWH?.width || 1;
471+
console.log(
472+
"pdfwh",
473+
containerScale,
474+
containerWH?.width / pdfOriginalWH?.width
475+
);
471476
let dropData = [];
472477
let placeHolder;
473478
const dragTypeValue = item?.text ? item.text : monitor.type;
474479
const widgetWidth = defaultWidthHeight(dragTypeValue).width;
475480
const widgetHeight = defaultWidthHeight(dragTypeValue).height;
481+
console.log("containerscale", containerScale, scale);
476482
if (item === "onclick") {
477483
const dropObj = {
478484
//onclick put placeholder center on pdf
@@ -514,14 +520,14 @@ function PlaceHolderSign() {
514520
const getYPosition = signBtnPosition[0]
515521
? y - signBtnPosition[0].yPos
516522
: y;
523+
console.log("getxyPos", getXPosition, getYPosition);
517524
const dropObj = {
518525
xPosition: getXPosition / (containerScale * scale),
519526
yPosition: getYPosition / (containerScale * scale),
520527
isStamp:
521528
(dragTypeValue === "stamp" || dragTypeValue === "image") && true,
522529
key: key,
523530
scale: containerScale,
524-
// isMobile: isMobile,
525531
zIndex: posZIndex,
526532
type: dragTypeValue,
527533
options: addWidgetOptions(dragTypeValue),
@@ -661,14 +667,13 @@ function PlaceHolderSign() {
661667

662668
//function for get pdf page details
663669
const pageDetails = async (pdf) => {
664-
pdf.getPage(1).then((pdfPage) => {
665-
const pageWidth = pdfPage.view[2];
666-
const pageHeight = pdfPage.view[3];
667-
setPdfOriginalWH({ width: pageWidth, height: pageHeight });
668-
const load = {
669-
status: true
670-
};
671-
setPdfLoadFail(load);
670+
const firstPage = await pdf.getPage(1);
671+
const scale = 1;
672+
const { width, height } = firstPage.getViewport({ scale });
673+
// console.log("width height", width, height);
674+
setPdfOriginalWH({ width: width, height: height });
675+
setPdfLoadFail({
676+
status: true
672677
});
673678
};
674679

0 commit comments

Comments
 (0)