Unable to link to inserted pages with pdfpages
The inserted link
is a hyper-link, not a LaTeX \label
. Therefore the \hyperlink
macro works but not the \pageref
. I don't think you can get the page information from a hyper-link, so I think you need to add \label
s manually. This can be done best using the pagecommand
key and a custom counter:
\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}
\newcounter{includepdfpage}
\begin{document}
See page \pageref{testing.1} till \pageref{testing.10}.
\hyperlink{testing.1}{Hello.}
\includepdf[pages=-,link,linkname=testing,pagecommand={\refstepcounter{includepdfpage}\label{testing.\theincludepdfpage}}]{test.pdf}
\end{document}
Just for reference, here is the solution I ended up using. It is based on the answer of Martin Scharrer, but modified to work with several inserted documents.
\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}
\newcounter{includepdfpage}
\newcounter{currentpagecounter}
\newcommand{\addlabelstoallincludedpages}[1]{
\refstepcounter{includepdfpage}
\stepcounter{currentpagecounter}
\label{#1.\thecurrentpagecounter}}
\newcommand{\modifiedincludepdf}[3]{
\setcounter{currentpagecounter}{0}
\includepdf[pages=#1,pagecommand=\addlabelstoallincludedpages{#2}]{#3}}
\begin{document}
See page \pageref{one.1} till \pageref{two.3}.
\modifiedincludepdf{-}{one}{test.pdf}
\modifiedincludepdf{-}{two}{test.pdf}
\end{document}