TLDR
Use
- pdftk if want a command-line interface,
- pdfsam if you want graphical user interface,
- sejda if you want a web interface.
They are free (as in beer and speech) and available for most operating systems.
I have no idea why most tools do not preserve hyper links.
Method
For a list of possible solutions -- that unfortunately do not discuss whenever links are preserved or not, cf. https://stackoverflow.com/q/2507766/2657549.
I'm testing with two copies of the following file, that I named a.pdf
and b.pdf
:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{bib.bib}
@misc{ex,
author={Doe, Jack},
title={An Example}
}
\end{filecontents*}
\usepackage{biblatex}
\addbibresource{bib.bib}
\usepackage{hyperref}
\begin{document}
\section{A section}
\label{section}
url: \href{https://tex.stackexchange.com/a/531215/34551}{this post}
reference: \cite{ex}
internal link: \ref{section}
file link: \href{run:a.pdf}{file}
\printbibliography
\end{document}
I combined them into a tot.pdf
file using the following tools, and tested whenever the url, the reference and the internal links were preserved in both documents or not.
+-----------+----------------------------------------------------------------------------+------+-------+-------+------+
| Software | Command | url | ref. | link | file |
+-----------+----------------------------------------------------------------------------+------+-------+-------+------+
| convert | convert a.pdf b.pdf tot.pdf | ✗ | ✗ | ✗ | ✗ |
| pdfjam | pdfjam a.pdf b.pdf -o tot.pdf | ✗ | ✗ | ✗ | ✗ |
| gs | gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=tot.pdf a.pdf b.pdf | ✗ | ✗ | ✗ | ✗ |
| pdfunite | pdfunite a.pdf b.pdf tot.pdf | ✓ | ✗ | ✗ | ✓ |
| pdftk | pdftk a.pdf b.pdf cat output tot.pdf | ✓ | ✓ | ✓ | ✓ |
| pdfsam | (it's a gui) | ✓ | ✓ | ✓ | ✓ |
| sejda.com | (it's a website) | ✓ | ✓ | ✓ | ✓ |
+-----------+----------------------------------------------------------------------------+------+-------+-------+------+
(Note that the links to files are not converted to internal anchor if the document that was referenced is being merged. I don't think that this is even feasible without re-writting the LaTeX source code.)
Versions
- convert: ImageMagick 6.9.10-23 Q16 x86_64 20190101
- pdfjam: This is pdfjam version 3.03.
- gs: GPL Ghostscript 9.27 (2019-04-04)
- pdfunite: version 0.71.0
- pdftk: port to java 3.0.2 a Handy Tool for Manipulating PDF Documents
- pdfsam: PDF Split And Merge Basic Edition 4.0.1
- https://www.sejda.com/merge-pdf does not mention any version, but was tested on 2020/03/04.
Licences and Pricing
Other options
Not tested:
qpdf
can at least remove encryption from PDFs without breaking hyperlinks, you might give it a try.combine
to merge documents in a convenient way (optinal index of the documents, general list of figures, etc.)xr
package and final PDF combination? might be of interest.pdfpages
, and only documented there. Lots of tweaks available, also keeping hyperlinks (not done by default, though). It is part of TeXlive.