Graphics, Figures & Tables ⇒ Embed clickable Pictures in a PDF Document
Embed clickable Pictures in a PDF Document
Is there a way to place a small clickable icon in a PDF such that, once clicked on it, it brings a large picture to the front (using the default OS viewer) ?
Ideally, the large picture should be included in the PDF document, but stay invisible by default. The clickable visible icon is the "door" to the large picture.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Embed clickable Pictures in a PDF Document
Here is a solution based on JavaScript. It requires AdobeReader, though. There is only one image file, the final one at final resolution, to be embedded. It is scaled down to the size of a thumbnail using the `scale` option of `\includegraphics`. When it is clicked on, it will be enlarged to fit into the document window of the Reader, when clicked again, Reader zoomes out again.
The code example below defines the command `\zoombox[<box line width>]{<contents>}` where the optional `<box line width>` controls the width of the dotted line around the zoom box to be created. The content for zooming can be arbitrary material, such as text or a downscaled graphic, and is put into the mandatory second argument of `\zoombox`.
Code: Select all
% (C) 2011, Alexander Grahn, Lic: Public Domain
\documentclass{article}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newsavebox\zbox
\newcounter{zoom}
\newcommand{\zoombox}[2][0]{%
\leavevmode%
\sbox\zbox{#2}%
\pdfdest name {zb\thezoom.out} fit
\pdfdest name {zb\thezoom.in} fitr
width \the\wd\zbox\space
height \the\ht\zbox\space
depth \the\dp\zbox\space
\immediate\pdfannot
width \the\wd\zbox\space
height \the\ht\zbox\space
depth \the\dp\zbox\space
{%
/Subtype/Link/H/N
/Border [0 0 #1 [1 2]]
/A <<
/S/JavaScript
/JS (
if(typeof(zoomed\thezoom)=='undefined'){
this.gotoNamedDest('zb\thezoom.out');
var zoomed\thezoom=false;
}
)
/Next <<
/S/GoTo/D (zb\thezoom.in)
/Next <<
/S/JavaScript
/JS(
if(zoomed\thezoom){
this.gotoNamedDest('zb\thezoom.out');
zoomed\thezoom=false;
}else{
zoomed\thezoom=true;
}
)
>>
>>
>>
}%
\usebox{\zbox}%
\stepcounter{zoom}%
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\zoombox{\includegraphics[scale=.05]{tiger}}
\end{document}
Embed clickable Pictures in a PDF Document

Is there an "universal" way to define a "zoombox" in pdfLaTeX ?
Embed clickable Pictures in a PDF Document
As I said, a PDF Reader with JavaScript interpreter is needed for the above example to fully work. The most reliable one is Adobe Reader, Evince (open-source) or Foxit may work as well but I didn't test.Cham wrote:Is there an "universal" way to define a "zoombox" in pdfLaTeX ?
Any PDF reader should at least fulfil the PDF specification and allow for zooming-in on the first click. The JavaScript in my example is only needed to zoom-out on the second click. It seems that Preview is not a conforming PDF reader, something that Adobe cannot be blamed for.