# hyperlink in toc to pdf-image

I was able to build a table of contents that directs me to each chapter, as in this example: toc with hyperlinks. My code:

\documentclass{book}
\usepackage[left=1.5cm,right=1.5cm]{geometry}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{booktabs,newtxtext,newtxmath,multirow}
\usepackage{ltablex}
\usepackage{sectsty}
\chapterfont{\color{darkblue2}}
\renewcommand{\thepage}{\textcolor{darkblue2}{\arabic{page}}}
\usepackage{hyperref}
\pagecolor{white}
\usepackage{pdfpages,graphics}
\definecolor{lilita}    {RGB}{215,205,247}
\definecolor{darkblue2} {rgb}{0,0,0.7}
\pagestyle{plain}
\begin{document}
\pagecolor{lilita}
{\makeatletter
\let\@oldstarttoc\@starttoc
\renewcommand{\@starttoc}{%
\@oldstarttoc}
\tableofcontents
\makeatother}
\include{i}
\include{u}
\end{document}


in file 'i.tex' and 'u.tex' I put

\phantomsection


to generate the "entrance" in toc. The hyperlink takes me, correctly, to the page where each chapter begins. Each chapter has as first page an image which I generated elsewhere and is included in the file: portadas. What I would like to obtain is that the hyperlink takes me to this image instead of "page 2" of each chapter. Is it possible?

• \clearpage \phantomsection \addcontentsline{toc}{chapter}{I} \includepdf[pages=1]{portadas} should give you a toc entry that points to the top of the included pdf. – leandriis Jun 16 '18 at 7:21
• Not working. The hyperlink keeps directing me to "page 2". Also, I marked the previous posts. Thanks – Antonio Ortiz Jun 16 '18 at 12:21

The following MWE demonstrates the different output that can be obtained by a different position of the \addcontentsline command in the code.

In the first example, the command is placed before \includepdf and the hyperlink in the table of contents correctly leads to the page with the included pdf.

In the second example, the \addcontentsline command is placed after the \includepdf command and thus the hyperlink in the toc leads to the page after the included pdf.

\documentclass{book}
\usepackage[left=1.5cm,right=1.5cm]{geometry}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{This takes me to the included pdf}

%%%%%%%%%%% The following could also be in 'i.tex'%%%%%
Some text that represents the contents of i.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%