11

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).

lockstep
  • 250,273
  • 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 05 '11 at 20:21
  • @Caramdir Thanks. I used the "index" tag since Evince uses that name in the sidebar. My bad. – latexnewbie Mar 05 '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 05 '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 07 '11 at 09:36

3 Answers3

9

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)

Martin Scharrer
  • 262,582
  • 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 05 '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 05 '11 at 22:53
0

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?

jrhorn424
  • 792
  • @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 05 '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=false]{file3.pdf} where the specified section starts on page 5 of file3.pdf. – latexnewbie Mar 05 '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 05 '11 at 20:28
  • @latexnewbie: Someone else may know how to accomplish that. My LaTeX knowledge isn't that advanced. However, it sounds like a hack would be brittle. If you won't be changing the text, rearranging sections, or adding new figures, I'm not sure what the appeal of using LaTeX is. If this is a one-off project anyway, I recommend making a TOC in OpenOffice (or any text editor), printing it as PDF, and pasting it all together using Evince. – jrhorn424 Mar 05 '11 at 20:29
  • 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 05 '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 05 '11 at 20:57
0

Merging pdf files with table of contents:

\documentclass{book}
\usepackage{pdfpages}
\usepackage{hyperref}
\usepackage{tocloft}

\begin{document} \frontmatter \tableofcontents %\mainmatter { \renewcommand{\cleardoublepage}{\newpage} \mainmatter } \clearpage \phantomsection\addcontentsline{toc}{chapter}{Cover letter} \includepdf[pages=-]{cover_lett.pdf} \clearpage \phantomsection\addcontentsline{toc}{chapter}{Research statement} \includepdf[pages=-]{research_stm.pdf}

\phantomsection\addcontentsline{toc}{chapter}{CV} \includepdf[pages=-]{cv_ab.pdf}

\end{document}

Ani
  • 21