pdf-tools/saveLoadPdf.ts
2025-04-22 14:21:58 -06:00

16 lines
432 B
TypeScript

import { PDFDocument } from "pdf-lib";
export async function loadPdfForm(path: string) {
const pdfBytes = await Deno.readFile(path);
const pdfDoc = await PDFDocument.load(pdfBytes);
const form = pdfDoc.getForm()
return form;
}
export async function savePdf(doc: PDFDocument, path: string) {
const pdfBytes = await doc.save();
if (Deno.env.get("DRYRUN")) return
await Deno.writeFile(path, pdfBytes);
}