mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
27 lines
770 B
TypeScript
27 lines
770 B
TypeScript
import { PDFDocument } from '@cantoo/pdf-lib';
|
|
|
|
export async function insertImageInPDF(
|
|
pdfAsBase64: string,
|
|
image: string | Uint8Array | ArrayBuffer,
|
|
positionX: number,
|
|
positionY: number,
|
|
page = 0,
|
|
): Promise<string> {
|
|
const existingPdfBytes = pdfAsBase64;
|
|
const pdfDoc = await PDFDocument.load(existingPdfBytes);
|
|
const pages = pdfDoc.getPages();
|
|
const pdfPage = pages[page];
|
|
const pngImage = await pdfDoc.embedPng(image);
|
|
const drawSize = { width: 192, height: 64 };
|
|
|
|
pdfPage.drawImage(pngImage, {
|
|
x: positionX,
|
|
y: pdfPage.getHeight() - positionY - drawSize.height,
|
|
width: drawSize.width,
|
|
height: drawSize.height,
|
|
});
|
|
|
|
const pdfAsUint8Array = await pdfDoc.save();
|
|
return Buffer.from(pdfAsUint8Array).toString('base64');
|
|
}
|