-
-
Notifications
You must be signed in to change notification settings - Fork 840
Closed
Description
Hi, I use pdf-lib to combine multiple PDFs. One of the PDFs has links in it, like a table of contents. The links direct to other pages of the same PDF. the problem is that these links are lost after combining PDFs with pdf-lib.
Is there a way to preserve the links?
My code:
const pdfDoc = await PDFDocument.create();
for (const file of files) {
const indices = [];
for (let i = 0; i < file.getPageCount(); i++)
indices.push(i);
const pages = await pdfDoc.copyPages(file, indices);
for (const page of pages) {
pdfDoc.addPage(page);
}
}Edit: I found out that the links are saved as "Named Destinations" in the PDF. The PDF has Version 1.4. One option would be that I add the destinations after merging, but then I need an option to add these to the pdf manually.