Add bookmarks to included PDF and get ToC entry as clickable link

bookmarkshyperreftable of contentstocloft

First: I'm not sure if this should be two separate questions but I've decided to post them as one.

Consider the following MWE (follow-up to Error regarding \contentsline when compiling):

\documentclass{article}

\usepackage{tocloft}
\usepackage{pdfpages}
\usepackage{hyperref}


\begin{document}

\tableofcontents
\newpage

\section{A section}
\label{section:A}
Test
\newpage

\section{External document}
The following pages consist of external documents.

\phantomsection
\addtocontents
  {toc}
  {\protect
   \contentsline
     {subsection}
     {\protect\numberline{}Dummy Page}
     {4}
     {}}
\includepdf[pages = -]{dummy.pdf}

\end{document}
  1. How do I make the added ToC entry Dummy Page into a clickable link which directs me to the page where the dummy document starts (page 4, in this case)?

  2. How do I add a bookmark entry called Dummy Page with the correct page number (here, 4)?

Best Answer

\documentclass{article}

\usepackage{tocloft}
\usepackage{pdfpages}
\usepackage{hyperref}


\begin{document}

\tableofcontents
\newpage

\section{A section}
\label{section:A}
Test
\newpage

\section{External document}
The following pages consist of external documents.

\newpage
\phantomsection
\addcontentsline{toc}{subsection}{\protect\numberline{}Dummy Page}
\includepdf[pages = -]{example-image}

\end{document}
Related Question