33

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.

1
  • @gull there is already an accepted answer so I think the posters problem was solved in 2011.
    – dustin
    Commented Aug 12, 2013 at 10:12

1 Answer 1

37

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}
13
  • Interesting/disappointing that pdfpages' linktotoc option is harder than just doing this manually, since the rest of the package is excellent. Commented Feb 14, 2011 at 21:35
  • @Will do you mean addtotoc?
    – mankoff
    Commented Feb 14, 2011 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
    Commented Feb 14, 2011 at 22:12
  • 1
    @mankoff: I edited the answer. There is now a working example.
    – user2478
    Commented Feb 14, 2011 at 22:25
  • 1
    I have no problem with \documentclass{book} and changing section to chapter
    – user2478
    Commented Mar 3, 2014 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .