(pdfOriginalWH, pdfDoc, documentId)
| 1503 | |
| 1504 | //function for embed document id |
| 1505 | export const embedDocId = async (pdfOriginalWH, pdfDoc, documentId) => { |
| 1506 | const appName = "OpenSign™"; |
| 1507 | // `fontBytes` is used to embed custom font in pdf |
| 1508 | const fontBytes = await fileasbytes( |
| 1509 | "https://cdn.opensignlabs.com/webfonts/times.ttf" |
| 1510 | ); |
| 1511 | pdfDoc.registerFontkit(fontkit); |
| 1512 | const font = await pdfDoc.embedFont(fontBytes, { subset: true }); |
| 1513 | //pdfOriginalWH contained all pdf's pages width and height |
| 1514 | for (let i = 0; i < pdfOriginalWH?.length; i++) { |
| 1515 | const fontSize = 10; |
| 1516 | const textContent = documentId && `${appName} DocumentId: ${documentId} `; |
| 1517 | const pages = pdfDoc.getPages(); |
| 1518 | const page = pages[i]; |
| 1519 | const getSize = pdfOriginalWH[i]; |
| 1520 | try { |
| 1521 | const getObj = compensateRotation( |
| 1522 | page.getRotation().angle, |
| 1523 | 10, |
| 1524 | 5, |
| 1525 | 1, |
| 1526 | getSize, |
| 1527 | fontSize, |
| 1528 | rgb(0.5, 0.5, 0.5), |
| 1529 | font, |
| 1530 | page |
| 1531 | ); |
| 1532 | page.drawText(textContent, getObj); |
| 1533 | } catch (err) { |
| 1534 | console.log("Err in embed docId on page", i + 1, err?.message); |
| 1535 | } |
| 1536 | } |
| 1537 | }; |
| 1538 | |
| 1539 | // function for convert input text value in image |
| 1540 | export function convertTextToImg(fontStyle, text, color, widgetDims) { |
no test coverage detected