32

How can I add a Table of Contents (TOC) to an existing PDF?

I have an existing PDF (scanned notes from a class). I'd like to improve this basic scan as much as possible. I do not think that any OCR is good enough to recognize handwriting, so I cannot make it searchable. But I would like to manually modify it by adding a TOC in the beginning that links to parts of the document.

One way could be to split the PDF into separate documents, then have:

\section{Part One}
\include{part1.pdf}
\section{Part Two}
\include{part2.pdf}

But I am wondering if there is a way to do this without splitting it up.

  • @gull there is already an accepted answer so I think the posters problem was solved in 2011. – dustin Aug 12 '13 at 10:12
35

use package pdfpages and then:

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

\tableofcontents
\clearpage\phantomsection
\addcontentsline{toc}{section}{The first section name}% or chapter
\includepdf[pages={1-10},linktodoc,linktodocfit=/Fit]{texte/dtk/dtk11-1/komoedie.pdf}
\clearpage\phantomsection
\addcontentsline{toc}{section}{The second section name}% or chapter
\includepdf[pages={11-19},linktodoc,linktodocfit=/Fit]{texte/dtk/dtk11-1/komoedie.pdf}
\clearpage\phantomsection
\addcontentsline{toc}{section}{The third section name}% or chapter
\includepdf[pages={20-29},linktodoc,linktodocfit=/Fit]{texte/dtk/dtk11-1/komoedie.pdf}
\clearpage\phantomsection
\addcontentsline{toc}{section}{The forth section name}% or chapter
\includepdf[pages={21-39},linktodoc,linktodocfit=/Fit]{texte/dtk/dtk11-1/komoedie.pdf}

\end{document}
  • Interesting/disappointing that pdfpages' linktotoc option is harder than just doing this manually, since the rest of the package is excellent. – Will Robertson Feb 14 '11 at 21:35
  • @Will do you mean addtotoc? – mankoff Feb 14 '11 at 21:58
  • @Herbert Thank. It sort-of works. It appears correct, but the TOC links (and sidebar links) all go to the bottom of the local TeX text document. (page 2, after the TOC and title page). The TOC link says "page 17", but just jumps to the bottom of the local doc (the top of all the included pages). – mankoff Feb 14 '11 at 22:12
  • 1
    @mankoff: I edited the answer. There is now a working example. – user2478 Feb 14 '11 at 22:25
  • 1
    I have no problem with \documentclass{book} and changing section to chapter – user2478 Mar 3 '14 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.