0

I modified this answer to include PDFs in my file.

MWE

\documentclass{report}

\usepackage{pdfpages}

\usepackage{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\usepackage[colorlinks]{hyperref}


\newcommand{\insertmydocument}[4]%
           { % Syntax: \insertmydocument{Toc level}{Title}{File}
             % Requires: tocloft hyperref pdfpages
             \newpage
             \phantomsection
             \cftaddtitleline{toc}{#1}{#2}{\thepage}
            \includepdf[pages=-]{#3}
           }


\begin{document}


\tableofcontents

\chapter{A regular chapter}

\insertmydocument{chapter}{A pdf}{document}

\chapter{Another chapter}

\end{document}

Problem

The included PDF doesn't appear in the bookmark section of my pdf viewer.

enter image description here

Can somebody explain me why and how to solve the problem?

2

\cftaddtitleline doesn't create bookmarks.

You can add them e.g. with bookmark:

\documentclass{report}

\usepackage{pdfpages}

\usepackage{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\usepackage[colorlinks]{hyperref}
\usepackage{bookmark}

\newcommand{\insertmydocument}[4]%
           { % Syntax: \insertmydocument{Toc level}{Title}{File}
             % Requires: tocloft hyperref pdfpages
             \newpage
             \phantomsection
             \bookmark[level=chapter,dest=\csname @currentHref\endcsname]{#2}%
             \cftaddtitleline{toc}{#1}{#2}{\thepage}
            \includepdf[pages=-]{#3}
           }


\begin{document}


\tableofcontents

\chapter{A regular chapter}

\insertmydocument{chapter}{A pdf}{example-image}

\chapter{Another chapter}

\end{document}

enter image description here

  • Great solution! In my file I changed level=chapter to level=#1 so that the bookmarks have the same structure (chapter, section, subsection...) like the document. – Sr. Schneider Jul 25 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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