documenso/packages/lib/server-only/pdf/insert-form-values-in-pdf.ts
Lucas Smith 9035240b4d
refactor: replace pdf-sign with libpdf/core for PDF operations (#2403)
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
2026-01-21 15:16:23 +11:00

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));
};