initial cli api, some movement on tool selection
This commit is contained in:
19
util/saveLoadPdf.ts
Normal file
19
util/saveLoadPdf.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { PDFDocument } from "pdf-lib";
|
||||
|
||||
export async function loadPdfForm(path: string) {
|
||||
const pdfDoc = await loadPdf(path);
|
||||
const form = pdfDoc.getForm();
|
||||
return form;
|
||||
}
|
||||
|
||||
export async function loadPdf(path: string) {
|
||||
const pdfBytes = await Deno.readFile(path);
|
||||
const pdfDoc = await PDFDocument.load(pdfBytes);
|
||||
return pdfDoc;
|
||||
}
|
||||
|
||||
export async function savePdf(doc: PDFDocument, path: string) {
|
||||
const pdfBytes = await doc.save();
|
||||
if (Deno.env.get("DRYRUN") || path.includes("dryrun")) return;
|
||||
await Deno.writeFile(path, pdfBytes);
|
||||
}
|
Reference in New Issue
Block a user