I am using python and pdftk to create a portfolio from many pdf files. About half the files are generate by LaTeX and the other half are scanned in documents. When I am done, I want to create a table of contents with hyperlinks to specific pages in the final, assembled document. I have a table of contents that I have generated with correct page numbers for each document. It looks nice (in my opinion), but the hyperlinks don't work. I believe the problem is that the toc tex file is only one page, so links to other pages don't seem to work. Here is my code for the toc file:
\input{toc_header}
\begin{document}
\begin{center}
\begin{tabularx}{0.95\textwidth}{Xr}
{\large \textbf{Table of Contents}} & page \\
Table of Contents & \hyperlink{page.2}{2} \rule{0pt}{1.2EM} \\
\hline
CV & \hyperlink{page.3}{3} \rule{0pt}{1.2EM} \\
\hline
Support Letter from Nominator & \hyperlink{page.7}{7} \rule{0pt}{1.2EM} \\
\hline
Section 1: Philosophy of Teaching & \hyperlink{page.10}{10} \rule{0pt}{1.2EM} \\
\hline
Section 2: Implementation and Outcomes of the Teaching Philosophy & \hyperlink{page.12}{12} \rule{0pt}{1.2EM} \\
\hline
\hspace{0.25in} 2. A: Evidence of Acting on Teaching Evaluations & \hyperlink{page.13}{13} \rule{0pt}{1.2EM} \\
\hline
\hspace{0.25in} 2. B: Examples of How My Teaching Philosophy Has Been Implemented & \hyperlink{page.26}{26} \rule{0pt}{1.2EM} \\
\hline
\hspace{0.25in} 2. C: Evidence of the Effectiveness of My Teaching & \hyperlink{page.45}{45} \rule{0pt}{1.2EM} \\
\hline
\hspace{0.25in} 2. D: Syllabi for the Past Three Semesters & \hyperlink{page.58}{58} \rule{0pt}{1.2EM} \\
%many more entries
\end{tabularx}
\end{center}
\end{document}
Is there any way to create a single page document like this with links to pages that technically don't exist, so that when I merge it with other pdfs using pdftk, the hyperlinks work?
Best Answer
pdfpages
can be used to embed PDFs in a document and to add entries to the ToC.Assuming you have a file
kant.pdf
, which you want to embed in your main file, you could do so by callingincludepdf
with the following parameters:Here is a minimal kant paper:
And a main file, which includes
kant.pdf
and sets three bookmarks (to the title and the two sections):If you prefer keeping your existing table, then don't use
\tableofcontents
and use\pageref
instead of\hyperlink
:Caveat: Links (and annotations) in the included pdf files are lost.
If you want consistent page numbers, headers and/or footers, you can define a pagestyle and use it with the option
pagecommand
(the default ispagecommand={\thispagestyle{empty}}
).