1

I want to make a normal section, shown in the table of contents with hyperref enabled, but instead of section heading I want to insert a PDF. I already tried to just hide the section heading by setting it's size to 0pt but this resulted in a blank page followed by my PDF.

For a little bit more context: The PDF contains a bill of materials wich has to be visible in the table of contents with the correct page number linked.

Including the PDF as an image also isn't an option because the document has to be searchable.


My code currently looks like this:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,right=2.5cm,marginparwidth=1.75cm]{geometry}
\usepackage{hyperref}
\usepackage{pdfpages}

\begin{document}

\tableofcontents \newpage

\section{Bill of Materials} \includepdf{billofmaterials.pdf}

\end{document}

ole
  • 43

2 Answers2

1

I now found a solution with the help of these two articles:

Include PDF and Section into one site and Hide part and chapter headings

My code now looks like this and it does the trick:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,right=2.5cm,marginparwidth=1.75cm]{geometry}
\usepackage{hyperref}
\usepackage{pdfpages}
\usepackage[explicit]{titlesec}

\newcommand*\Hide{ \titleformat{\section} {}{}{0pt}{} }

\begin{document}

\tableofcontents \newpage

\includepdf[pagecommand={\Hide \section{Bill of Materials} \thispagestyle{empty}},scale=1]{billofmaterials.pdf}

\end{document}

It's probably not the most elegant solution, but it works for me.

ole
  • 43
0

Use option addtotoc to add entries to the TOC.

\includepdf[
  addtotoc={1, section, 1, Bill of Materials, sec:bom}
]{billofmaterials.pdf}

I do not recommend to use option pagecommand like in the accepted answer. More often than not such solutions will break if you include a multipage PDF, because pagecommand is evaluated on each page.

  • Thank you, this solution is definitley more elegant. I would have inserted only one page per PDF anyways, but for people who would like to insert PDFs with more pages, this looks like the better solution. – ole Jan 09 '22 at 15:09