Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

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

1 Answer 1

up vote 31 down vote accepted

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}
share|improve this answer
    
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. –  Herbert Feb 14 '11 at 22:25
    
@mankoff — yes, sorry. My brain confused linktodoc and addtotoc. –  Will Robertson Feb 14 '11 at 23:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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