@@ -1248,6 +1248,7 @@ export const multiSignEmbed = async (
1248
1248
const newWidth = containerWH . width ;
1249
1249
const scale = newWidth / pdfOriginalWH . width ;
1250
1250
const pageNo = item . pageNumber ;
1251
+ console . log ( "page number" , pageNo ) ;
1251
1252
const imgUrlList = updateItem ;
1252
1253
const pages = pdfDoc . getPages ( ) ;
1253
1254
const form = pdfDoc . getForm ( ) ;
@@ -1261,10 +1262,6 @@ export const multiSignEmbed = async (
1261
1262
const newUrl = await convertPNGtoJPEG ( signUrl ) ;
1262
1263
signUrl = newUrl ;
1263
1264
}
1264
- // const checkUrl = urlValidator(signUrl);
1265
- // if (checkUrl) {
1266
- // signUrl = signUrl + "?get";
1267
- // }
1268
1265
const res = await fetch ( signUrl ) ;
1269
1266
return res . arrayBuffer ( ) ;
1270
1267
}
@@ -1480,21 +1477,23 @@ export const multiSignEmbed = async (
1480
1477
? breakTextIntoLines ( textContent , fixedWidth )
1481
1478
: NewbreakTextIntoLines ( textContent , fixedWidth ) ;
1482
1479
// Set initial y-coordinate for the first line
1483
- const labelDefaultHeight = defaultWidthHeight ( position . type ) . height ;
1484
-
1485
- let y = yPos ( position , null , labelDefaultHeight ) ;
1486
1480
let x = xPos ( position ) ;
1487
- //xPos( position)
1481
+ let y = position . yPosition ;
1488
1482
// Embed each line on the page
1489
1483
for ( const line of lines ) {
1490
- page . drawText ( line , {
1491
- x : x ,
1484
+ const correction = compensateRotation (
1485
+ page . getRotation ( ) . angle ,
1486
+ x ,
1492
1487
y ,
1488
+ 1 ,
1489
+ page . getSize ( ) ,
1490
+ fontSize ,
1491
+ updateColorInRgb ,
1493
1492
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
1498
1497
}
1499
1498
} else if ( position . type === "dropdown" ) {
1500
1499
const dropdownRandomId = "dropdown" + randomId ( ) ;
@@ -1506,13 +1505,23 @@ export const multiSignEmbed = async (
1506
1505
dropdown . select ( position ?. options ?. defaultValue ) ;
1507
1506
}
1508
1507
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 ,
1512
1518
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 ) ;
1516
1525
dropdown . enableReadOnly ( ) ;
1517
1526
} else if ( position . type === radioButtonWidget ) {
1518
1527
const radioRandomId = "radio" + randomId ( ) ;
@@ -1535,7 +1544,37 @@ export const multiSignEmbed = async (
1535
1544
y : yPosition + 2 ,
1536
1545
size : 11
1537
1546
} ) ;
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);
1538
1567
}
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);
1539
1578
radioGroup . addOptionToPage ( data , page , {
1540
1579
x : xPos ( position ) ,
1541
1580
y : yPosition ,
@@ -1560,12 +1599,14 @@ export const multiSignEmbed = async (
1560
1599
width : scaleWidth ,
1561
1600
height : scaleHeight
1562
1601
} ;
1602
+
1563
1603
const imageOptions = getImagePosition ( page , signature , 1 ) ;
1564
1604
page . drawImage ( img , imageOptions ) ;
1565
1605
}
1566
1606
} ) ;
1567
1607
}
1568
1608
const pdfBytes = await pdfDoc . saveAsBase64 ( { useObjectStreams : false } ) ;
1609
+ // console.log("pdf", pdfBytes);
1569
1610
return pdfBytes ;
1570
1611
} ;
1571
1612
@@ -2077,8 +2118,76 @@ export async function findContact(value) {
2077
2118
}
2078
2119
2079
2120
// `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
+ ) {
2082
2191
let rotationRads = ( pageRotation * Math . PI ) / 180 ;
2083
2192
2084
2193
//These coords are now from bottom/left
@@ -2121,17 +2230,30 @@ function compensateRotation(pageRotation, x, y, scale, dimensions, fontSize) {
2121
2230
drawX = coordsFromBottomLeft . x ;
2122
2231
drawY = coordsFromBottomLeft . y ;
2123
2232
}
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
+ }
2125
2245
}
2126
2246
2127
2247
// `getImagePosition` is used to calulcate position of image type widget like x, y, width, height for pdf-lib
2128
2248
function getImagePosition ( page , image , sizeRatio ) {
2129
2249
let pageWidth ;
2130
2250
// pageHeight;
2131
2251
if ( [ 90 , 270 ] . includes ( page . getRotation ( ) . angle ) ) {
2252
+ console . log ( "go in 90 degree" ) ;
2132
2253
pageWidth = page . getHeight ( ) ;
2133
2254
// pageHeight = page.getWidth();
2134
2255
} else {
2256
+ console . log ( "go in 180 degree" ) ;
2135
2257
pageWidth = page . getWidth ( ) ;
2136
2258
// pageHeight = page.getHeight();
2137
2259
}
0 commit comments