1

I'm merging some PDFs using pdfpages and I would like to add some phantom bookmarks to make a clickable table of context on the side of my final PDF (I imagine using hyperref), a bit like this or like this. I've tried adding \section{section one}, etc., but I still don't get the usual interactive table of content in my final PDF. I also tried looking in pdfpages manual, but until now with no luck. Can someone here help me solve this?

Code (you need some random file_01.pdf and file_02.pdf),

\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}

\begin{document}
\pagenumbering{roman}
\includepdf[pages=1-7]{file_01.pdf}
\pagenumbering{arabic}
\includepdf[pages=8-]{file_01.pdf}
\includepdf[pages=-]{file_02.pdf}
\end{document}
Eric Fail
  • 1,077
  • Do you have any indication that this is supported by the package? From pdfpages.pdf: When including pages of a PDF only the so called content stream of these pages is copied but no links. [...] Some links may be extracted and later reinserted by a package called pax which can be downloaded from CTAN. Have you checked out pax? – gernot Nov 01 '16 at 15:48
  • Hadn't seen that, thanks! However, it seems as pax is a program intended for preserving an­no­ta­tions across merges. I want to add my own (new) bookmarks/phantom sections to the merged PDF. – Eric Fail Nov 01 '16 at 16:34

1 Answers1

4

\includepdf has option pagecommand, which can be used to insert an entry for the table of contents:

\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}

\begin{document}
\tableofcontents
\pagenumbering{roman}
\includepdf[
  pages=1,
  pagecommand=\phantomsection\addcontentsline{toc}{section}{File 01, Page 1},
]{file_01.pdf}
\includepdf[
  pages=2,
  pagecommand=\phantomsection\addcontentsline{toc}{section}{File 02, Page 2},
]{file_01.pdf}
\end{document}

\phantomsection creates an anchor for the following \addcontentsline. hyperref catches \addcontentsline for the bookmarks.

If the precise location for the link target inside the included pages is needed, then the \phantomsection can be placed via environment picture (with size zero).

Alternatively the link targets of the included PDF files can be imported via PAX. If bookmarks are needed only, they can then be set via package bookmark, even outside of pagecommand.

Heiko Oberdiek
  • 271,626
  • Thanks! Would you have time to demonstrate the picture (with size zero) environment? My PDFs file_01.pdf and file_02.pdf is 50 and 53 pages respectively and I hope to add 3 or 4 sections to each. I see you used pages=1 and pages=2 for the two files (I take my initial post gave the impression that I am merging two pages from two PDFs). – Eric Fail Nov 07 '16 at 07:20
  • @EricFail Sorry, I do not understand the comment. – Heiko Oberdiek Nov 07 '16 at 17:39