Skip to content

Links are lost after combining PDFs #341

@vekunz

Description

@vekunz

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions