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.

I have a set of pdf files which I want to merge into a larger pdf files. Each individual pdf file is an article with sections. I am hoping to make the merged pdf file into a book format with each article being a chapter, whose sections and subsections correspond to that of the individual chapter.

What I need is a table of contents page which shows the chapters, the sections, and subsections and links to them with this table of contents page being displayed in the sidebar of a pdf reader such as evince (which calls it an index).

What I have right now:

\documentclass{report}
\author{<somename>}
\title{<sometitle>}
\date{<somedate>}
\usepackage{pdfpages}
\usepackage[pdfauthor={<somename>},%
        pdftitle={<sometitle>},%
        pdftex]{hyperref}

\begin{document}

\tableofcontents

\clearpage\phantomsection
\addcontentsline{toc}{chapter}{<chaptername>}
\includepdf[pages=-,linktodoc=false]{file1.pdf}

\clearpage\phantomsection
\addcontentsline{toc}{chapter}{<chaptername>}
\includepdf[pages=-,linktodoc=false]{file2.pdf}

\clearpage\phantomsection
\addcontentsline{toc}{chapter}{<chaptername>}
\includepdf[pages=-,linktodoc=false]{file3.pdf}

\clearpage\phantomsection
\addcontentsline{toc}{chapter}{<chaptername>}
\includepdf[pages=-,linktodoc=false]{file4.pdf}

\end{document}

Now file3.pdf and file4.pdf have sections and subsections in them. How do I display these sections and subsections in the table of contents and link from there to the actual page? (And I also would like this info to be displayed in the sidebar of a pdf reader such as evince).

share|improve this question
2  
I removed the {index} tag, as is generally used here to refer to the index (generally a list of words) at the end of a book. –  Caramdir Mar 5 '11 at 20:21
    
@Caramdir Thanks. I used the "index" tag since Evince uses that name in the sidebar. My bad. –  latexnewbie Mar 5 '11 at 20:40
2  
latexnewbie: No worry, it isn't a big thing. @Caramdir just wanted to explain things to you. The correct term and tag is {bookmarks} which I added now. –  Martin Scharrer Mar 5 '11 at 20:43
1  
Your question has a really long title. I'd suggest you make it a bit shorter. For starters, the part "(chapter ... etc)" could be deleted. –  Hendrik Vogt Mar 7 '11 at 9:36

2 Answers 2

up vote 7 down vote accepted

The entries in the "table of contents page [which is] being displayed in the sidebar of a pdf reader" are called PDF bookmarks in Adobe Acrobat. The hyperref and bookmark packages provide functionality to place own bookmarks into your PDF.

You should go for the bookmark package (which loads hyperref internally). It allows you to place links from the sidebar to specific pages of the current (or even an external) PDF with specific page, view port and zoom levels. You would need to collect the pages (and maybe zoom settings) for each (sub-)section by yourself if you don't have the LaTeX source of them.

An example for an bookmark entry which should appear in a certain hierarchy level and point to a certain page with a certain height (FitH) is:

\bookmark[level=<num>,page=<num>,view={FitH 842}]{<title>}

(See also the similar questions if you want to place links inside the document:
PDF hyperlinks to a given page.
pdfpages and linktodoc)

share|improve this answer
    
Thanks a ton. This is exactly what I wanted. I have one more question -- Can these bookmark commands be used to generate a ToC automatically? –  latexnewbie Mar 5 '11 at 22:48
    
@latexnewbie: About the ToC: I don't think so, you would need to create the entries with other macros. Feel free to open a follow-up question and ask about this, but add a link to this question. –  Martin Scharrer Mar 5 '11 at 22:53

I'm not sure having links in file3.pdf is possible without the LaTeX source, since, with a package like hyperref, the document processor uses headings and a counter to automatically link sections and subsections within the table of content.

The PDF document is, however, a final product. Unless each PDF already has bookmarks defined (bookmarks are what show up in the sidebar of something like Evince), I'm not sure how to accomplish this. I'm not even sure pdfpages would respect bookmarks.

If you can, why not create your frontmatter manually with LaTeX and use a graphical program, like Evince, to combine the PDFs into a single file?

share|improve this answer
    
@latexnewbie: OpenOffice has a feature called master documents that might be of use. Also, refer to this post to see how an author used OpenOffice to write his book. –  jrhorn424 Mar 5 '11 at 20:24
    
@jrhorn424 Thanks for such a quick reply. File3.pdf and File4.pdf are finished files. I don't have the latex source for them (they were created using openoffice) and they don't have any bookmarks specified within them. I was thinking if there was a way I could actually specify the page number of the section in file3.pdf. Something like \addcontentsline{toc}{chapter}{<chaptername>} \includepdf[pages=-,linktodoc=false]{file3.pdf} \addcontentsline{toc}{section}{<section-name>}\includepdf[pages=5,linktodock=fal‌​se]{file3.pdf} where the specified section starts on page 5 of file3.pdf. –  latexnewbie Mar 5 '11 at 20:28
    
@jrhorn424 Unfortunately I did not generate these pdf files and I also don't have the original openoffice files. –  latexnewbie Mar 5 '11 at 20:28
1  
@jrhorn424 Thanks for your help. The hack I am looking for is going to be very specific for the collection of files I have. I want to make a clickable ToC for online reading of the merged pdf file, so I don't think your suggestion for using OpenOffice to construct a ToC and then add it to the merged pdf will give me the desired result. –  latexnewbie Mar 5 '11 at 20:39
1  
@latexnewbie, @jrhorn424: Links to a certain page do not have to be on that page. You can link to any place on any PDF if you can specific the correct location. More or less its just a way to tell the PDF reader to "open PDF xyz on page P and zoom to XY". You could add links on the included pages (a quite different thing) using overlays, i.e. include the PDF using \includepdf and draw a hyperlinked box manually over the places which should be linked. Quite a bit of manual work, but it is possible. –  Martin Scharrer Mar 5 '11 at 20:57

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.