Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing outline when merging PDF files #308

Open
condorheroblog opened this issue Apr 21, 2023 · 1 comment
Open

Missing outline when merging PDF files #308

condorheroblog opened this issue Apr 21, 2023 · 1 comment

Comments

@condorheroblog
Copy link

condorheroblog commented Apr 21, 2023

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😉.

@rkusa
Copy link
Owner

rkusa commented Apr 21, 2023

Thanks for the report! This is probably similar to #130. I agree that it would be nice to have, but probably don't find the time to work on this myself anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants