15

In my document I include a PDF using

\includepdf[pages=-]{./mypdf.pdf}

The problem I'm having is how to add a TOC entry for this pdf.

It supposed to be an appendix. I tried adding a new section in the appendix but of course the section name can't be printed on the same page than the included pdf, so the resulting TOC line directs to a wrong page.

If I use \addcontentsline I loose the numbering and the page is wrong too because the included pdf actually starts at the next page...

I'm a bit lost here so I would really appreciate if someone knows how to do this.

Note: the pdf I try to include was not generated from LaTex.

Adam Smith
  • 2,584
  • 2
  • 20
  • 34
Heyyou'reQt
  • 153
  • 1
  • 1
  • 5
  • Haven't we had this question before? – Charles Stewart May 11 '10 at 07:57
  • I can't find an exact duplicate. The following link sounds really close, but the original poster accepted an answer that doesn't answer this question: http://stackoverflow.com/questions/2418871/need-to-merge-multiple-pdfs-into-a-single-pdf-with-table-of-contents-sections – Geoff May 11 '10 at 14:27

2 Answers2

19

From the documentation of pdfpages (page 6) it looks like there is an experimental tag called addtotoc. I think you'd use it like:

\includepdf[pages=-, addtotoc={<page number>, section, 1, <heading>, <label>}]

Where <page number> is the desired page number of the included PDF (edit) to link to, <heading> is the title in the TOC, and <label> is how you may \ref to the section.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Geoff
  • 7,935
  • 3
  • 35
  • 43
  • 3
    Thanks a lot, that's exactly the option I was looking for... I feel stupid not having looked inside the doc the pdfpages package... EDIT: is the number of the page that should be used as the reference in the TOC (so it's 1 most of the time) – Heyyou'reQt May 17 '10 at 16:02
  • Thanks for following up, I altered the answer to be more accurate. – Geoff May 17 '10 at 18:29
  • 1
    Hi Geoff and @Heyyou'reQt - see also [Include pdf and reference pages • Page Layout • LaTeX Community](http://www.latex-community.org/forum/viewtopic.php?f=47&t=7528): "_... puts an entry in the toc for **page 4 of the included pdf**..._" Cheers! – sdaau Jun 06 '12 at 14:08
  • Note that `heading` which will appear in TOC can include spaces, while `label` cannot contain spaces. – Adam Smith Sep 16 '19 at 15:27
0

Have you tried

\section[text for toc]{text for document}

in your case

\section[text for toc]{}

to suppress the output in the document.

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • That adds a line in the TOC with the right label but it still points to the wrong page, and even if the label isn't printed in the document, the appendix number still is ^^ That's why it still points to the wrong page. Isn't there a way to force the page number on which a toc label points? – Heyyou'reQt May 10 '10 at 15:20
  • Do you have a .toc file? You could try to edit that before the final compilation .. – aioobe May 10 '10 at 16:24