🚧 place signatures and text signatures

This commit is contained in:
Timur Ercan
2023-02-20 14:49:17 +01:00
parent 11eb557dbb
commit 44884ae648
10 changed files with 891 additions and 47 deletions

View File

@ -1,4 +1,4 @@
import { degrees, PDFDocument, PDFImage, rgb, StandardFonts } from "pdf-lib";
import { PDFDocument } from "pdf-lib";
export async function insertImageInPDF(
pdfAsBase64: string,
@ -12,12 +12,13 @@ export async function insertImageInPDF(
const pages = pdfDoc.getPages();
const pdfPage = pages[page];
const pngImage = await pdfDoc.embedPng(image);
const drawSize = { width: 213, height: 50 };
pdfPage.drawImage(pngImage, {
x: positionX,
y: positionY,
width: pngImage.width,
height: pngImage.height,
x: pdfPage.getWidth() - positionX - drawSize.width,
y: pdfPage.getHeight() - positionY - drawSize.height,
width: drawSize.width,
height: drawSize.height,
});
const pdfAsUint8Array = await pdfDoc.save();

View File

@ -1,4 +1,4 @@
import { degrees, PDFDocument, rgb, StandardFonts } from "pdf-lib";
import { PDFDocument, rgb, StandardFonts } from "pdf-lib";
export async function insertTextInPDF(
pdfAsBase64: string,
@ -13,10 +13,12 @@ export async function insertTextInPDF(
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
const pages = pdfDoc.getPages();
const firstPage = pages[page];
firstPage.drawText(text, {
x: positionX,
y: positionY,
const pdfPage = pages[page];
const lineHeightEsimate = 25;
pdfPage.drawText(text, {
x: pdfPage.getWidth() - positionX,
y: pdfPage.getHeight() - positionY - lineHeightEsimate,
size: 25,
font: helveticaFont,
color: rgb(0, 0, 0),