@alynva/outline-pdf-cjs
Version:
Add outline to outline-less pdf. Works in node and does not have any dependency on other programming languages.
26 lines (25 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.outlinePdfCjs = void 0;
const fs = require("fs");
const pdfLib = require("pdf-lib");
const outline_pdf_1 = require("@lillallol/outline-pdf");
const rejectIfPathExistsFactory_1 = require("./rejectIfPathExistsFactory");
const throwIfPathDoesNotEndWithPdf_1 = require("./throwIfPathDoesNotEndWithPdf");
/**
* @description
* Adds outline to an outline-less pdf.
*/
async function outlinePdfCjs(_) {
const { loadPath, outline, savePath } = _;
const rejectIfPathExists = rejectIfPathExistsFactory_1.rejectIfPathExistsFactory(fs);
throwIfPathDoesNotEndWithPdf_1.throwIfPathDoesNotEndWithPdf(loadPath);
await rejectIfPathExists(savePath);
const outlinePdf = outline_pdf_1.outlinePdfFactory(pdfLib);
await outlinePdf.loadPdf(fs.readFileSync(loadPath));
outlinePdf.outline = outline;
outlinePdf.applyOutlineToPdf();
const pdf = await outlinePdf.savePdf();
fs.writeFileSync(savePath, pdf);
}
exports.outlinePdfCjs = outlinePdfCjs;