mirror of
https://github.com/documenso/documenso
synced 2026-04-21 21:37:18 +00:00
Migrate from @documenso/pdf-sign and @cantoo/pdf-lib to @libpdf/core for all PDF manipulation and signing operations. This includes: - New signing transports for Google Cloud KMS and local certificates - Consolidated PDF operations using libpdf API - Added TSA (timestamp authority) helper for digital signatures - Removed deprecated flatten and insert utilities - Updated tests to use new PDF library
25 lines
637 B
TypeScript
25 lines
637 B
TypeScript
import { PDF } from '@libpdf/core';
|
|
|
|
export type InsertFormValuesInPdfOptions = {
|
|
pdf: Buffer;
|
|
formValues: Record<string, string | boolean | number>;
|
|
};
|
|
|
|
export const insertFormValuesInPdf = async ({ pdf, formValues }: InsertFormValuesInPdfOptions) => {
|
|
const doc = await PDF.load(pdf);
|
|
|
|
const form = doc.getForm();
|
|
|
|
if (!form) {
|
|
return pdf;
|
|
}
|
|
|
|
const filledForm = Object.entries(formValues).map(([key, value]) => [
|
|
key,
|
|
typeof value === 'boolean' ? value : value.toString(),
|
|
]);
|
|
|
|
form.fill(Object.fromEntries(filledForm));
|
|
|
|
return await doc.save({ incremental: true }).then((buf) => Buffer.from(buf));
|
|
};
|