Merging PDF files in Linux while preserving the links

I wanted to merge multiple PDF files on Linux, without messing up the links in the individual files. There was a Linux.com article on merging PDF files using Ghostscript and using pdfmeld (a commercial software).

The Ghostscript method works, but completely messes the links up. Searching on Google also didn't return any instant pointers. But it did get me to pdftk. It's a really useful utility for meddling with PDF files.

To merge three PDF files, the command is:
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

And to make it even better, links work flawlessly in the merged PDF files. Hooray!

PS: I created the individual test files using OpenOffice Writer. They had navigational hyperlinks to sections inside the same files.

Update: It seems there's a good GUI for pdftk - PDF Chain. I haven't used it yet, but people seem to be appreciating it.
 
UPDATE 2 (2026-11-25): qpdf seems to be a more modern option that handles hyperlinks well. The command to merge two PDF files is:
qpdf --empty --pages 1.pdf 2.pdf -- merged.pdf
 
 If you are looking for an online option, PDF Fan seems great.
 
 

Comments

  1. Thank you, it was useful to learn about that, I was using pdfjoin, but it doesn't preserve my links!

    ReplyDelete
  2. Thanks. Happy to be of some help.
    This came up on Planet KDE a few days back:
    https://liquidat.wordpress.com/2015/04/05/short-tip-splitting-and-merging-pdf-files/
    Please do check it out. Might preserve links, but I don't know for sure.

    ReplyDelete
  3. A quick output check that helps here: test one web link and one internal table-of-contents link from a document placed second in the merge. The internal jump should land on the same section even though its page number has shifted. I maintain PDF Fan and have added our visual merge page in the URL field for readers looking for a browser option; I'd still run those two checks on the result.

    ReplyDelete
    Replies
    1. Thank you for your insights. I hadn't heard about PDF Fan, and honestly, had a difficult time finding it from google 🙂 It does seem to be an awesome online tool for managing PDF files. Many thanks for creating and maintaining a great free suite.

      These days, I use pdfunite from poppler to merge PDFs. But I haven't had the need to support hyperlinks. So I never checked if that worked. I followed your suggestion and created test files and found that pdfunite didn't support links.

      Then I tested and found that qpdf works well.

      Delete

Post a Comment

Popular posts from this blog

Fedora 16 / Windows 7 - Dual booting with GRUB2

Fedora 16 - Uninstall proprietary Nvidia driver and switch back to Nouveau

The woes of structure packing - #pragma pack