3

I'm making a image grid that links to pdfs. I want the pdf to link to the image too.

Neither the hypertarget to the image nor the hyperlink to the pdf work.

Are there any jump to page instructions in latex?

for example\hyperlink[page=12]{\includegraphics{img.jpg}}

Here is a MWE:

\documentclass{article}

% Media
\usepackage{pdfpages}
\usepackage{graphicx}

% Hyperlinks
\usepackage{hyperref}

\begin{document}

\hypertarget{anchor_a}{
    \hyperlink{anchor_b}{
        \includegraphics[width=0.25\textwidth]{img.jpg}
    }
}
\newpage
\hyperlink{anchor_a}{
    \hypertarget{anchor_b}{
        \includepdf[pages=-]{img.jpg}
    }
}
\includepdf[pages=-]{pdf.pdf}

\end{document}
0

1 Answer 1

0

I initially failed to include my real error (sorry it's my first time). It came from trying to do a nested hyperlink\hyperlink{anchor_a}{\hypertarget{anchor_b}{STUFF}}. I've updated the question. It's probably not supported.

I solved my problem by going off on the tangent and linking the image to a phantom character next to the big version of the image, and then doing the same for the big image. This produces the expected behavior.

\documentclass{article}

% Media
\usepackage{pdfpages}
\usepackage{graphicx}

% Hyperlinks
\usepackage{hyperref}

\begin{document}

% Targets phantom character of small image
\hypertarget{number_b}{ 
    \phantom{} % Makes 0 length character
} 
% Links to phantom character of the big image when clicking on the small image
\hyperlink{number_a}{   
    \includegraphics[width=0.25\textwidth]{number.jpg}
}

\newpage

% Big image phantom
\hypertarget{number_a}{
    \phantom{}
}
% Big image
\hyperlink{number_b}{
\includegraphics[width=\textwidth]{number.jpg}
}

\newpage

% Adds all the pages on the document with the pages=- option
\includepdf[pages=-]{number.pdf}

\end{document}

I figured from Using \hyperlink to link text to page with an implicit page anchor not known in advance that it's also possible jump to the page anchor to solve it:

\documentclass{article}

% Media
\usepackage{pdfpages}
\usepackage{graphicx}

% Hyperlinks
\usepackage{hyperref}

\begin{document}

\hyperlink{page.2}{ 
    \includegraphics[width=0.25\textwidth]{number.jpg}
}

\newpage

\hyperlink{page.1}{
\includegraphics[width=\textwidth]{number.jpg}
}

\newpage

% Adds all the pages on the document with the pages=- option
\includepdf[pages=-]{number.pdf}

\end{document}

The problem with this of course is that you have to know the size of the included pdf, and the location of both of the images in the page, so it makes it computationally expensive to include documents programmatically as you have to keep track of the page numbers. It's irrelevant for a few pages but it becomes an issue for anything more than 1000 pages long.

I implemented my solution in this ruby gist that takes an array of arrays as an input [ [first.jpg,first.pdf,first.name],...,[last.jpg,last.pdf,last.name] ] and outputs the phantom solution.

3
  • Your question is quite confusing. Do you want to link to page with the included pdf (that's easy, see the option link in the documentation) or from the page to somewhere else? Commented Oct 27, 2014 at 11:45
  • Sorry I'll rephrase my question. I want both to link to the included pdf and link back to the original linked image when clicking the first page of the pdf.
    – RJ Acuña
    Commented Oct 27, 2014 at 17:25
  • I've seen the documentation and I'm sorry that I'm being obtuse but I can't find the option link @UlrikeFischer.
    – RJ Acuña
    Commented Oct 27, 2014 at 17:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .