-
Notifications
You must be signed in to change notification settings - Fork 143
Open
Labels
Description
I use the following code to merge two PDFs, both of which have outlines. After merging, the newly generated PDF loses its outline. What should I do to ensure that the outline is preserved while merging PDFs.
const fs = require("node:fs");
const path = require("node:path");
const pdf = require("pdfjs");
const doc = new pdf.Document();
const pdf1 = fs.readFileSync(path.resolve(__dirname, "1.pdf"));
const pdf2 = fs.readFileSync(path.resolve(__dirname, "2.pdf"));
const ext1 = new pdf.ExternalDocument(pdf1);
const ext2 = new pdf.ExternalDocument(pdf2);
doc.addPagesOf(ext1);
doc.addPagesOf(ext2);
doc.asBuffer((err, data) => {
if (err)
console.error(err);
else
fs.writeFileSync("merge.pdf", data, { encoding: "binary" });
});
At present, I only know that the root outline can be obtained through the following code:
const fs = require("node:fs");
const Parser = require("./parser.js");
const parser = new Parser(fs.readFileSync("vitePress.pdf"));
parser.parse();
const getOutline = catalog.get("Outlines").object.properties;
Looking forward to your reply😉.
condorheroblogcondorheroblogcondorheroblog