The following code (for use with pdfLaTeX) defines the command \zoombox[box line width]{contents}. It creates a click-to-zoom box for fitting the second argument 'contents' into the AdobeReader window. A dotted line is drawn around the box if the optional 'box line width' is >0.
EDIT: The code has been optimized for presentation PDFs (such as beamer generated ones) looked at in full screen mode. The zoom-to box is now centred on the screen when clicked, as requested by @alfC.
\documentclass{beamer}
\usepackage{graphicx}
\usepackage{mwe}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \zoombox[box line width]{contents}
%
% optimized version for beamer: in full screen, zoom boxes are centred
% in the viewer; useable with any documenclass
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newsavebox\zb@x
\newcounter{z@@m}
\usepackage{calc}
\newdimen\B@r\newdimen\P@r
\newdimen\@zw\newdimen\@zh\newdimen\@zd
\newcommand{\zoombox}[2][0]{%
\leavevmode%
\sbox\zb@x{#2}%
\setlength\B@r{1pt*\ratio{\wd\zb@x}{\ht\zb@x+\dp\zb@x}}%
\setlength\P@r{1pt*\ratio{\paperwidth}{\paperheight}}%
\ifdim\B@r>\P@r\relax%
\setlength\@zw{\wd\zb@x}\setlength\@zh{\@zw*\ratio{\paperheight}{\paperwidth}}%
\setlength\@zd{(\@zh-\ht\zb@x-\dp\zb@x)*\real{0.5}+\dp\zb@x}%
\setlength\@zh{\@zh-\@zd}%
\else%
\setlength\@zh{\ht\zb@x+\dp\zb@x}%
\setlength\@zw{\@zh*\ratio{\paperwidth}{\paperheight}}%
\setlength\@zh{\ht\zb@x}\setlength\@zd{\dp\zb@x}%
\fi%
\makebox[0pt][l]{\makebox[\wd\zb@x][c]{\makebox[\@zw][l]{%
\pdfdest name {zbfs\thez@@m} fitr
width \@zw\space
height \@zh\space
depth \@zd\space
}}}%
\pdfdest name {zb\thez@@m} fitr
width \wd\zb@x\space
height \ht\zb@x\space
depth \dp\zb@x\space
\immediate\pdfannot
width \wd\zb@x\space
height \ht\zb@x\space
depth \dp\zb@x\space
{%
/Subtype/Link/H/N
/Border [0 0 #1 [1 2]]
/A <<
/S/JavaScript
/JS (
if(typeof(zoomed)=='undefined'||!zoomed){
var lastView=this.viewState;
if(app.fs.isFullScreen) this.gotoNamedDest('zbfs\thez@@m');
else this.gotoNamedDest('zb\thez@@m');
zoomed=true;
}else{
this.viewState=lastView;
zoomed=false;
}
)
>>
}%
\usebox{\zb@x}%
\stepcounter{z@@m}%
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{frame}
\zoombox{\includegraphics[width=1cm]{example-image-a}}
\zoombox{\includegraphics[width=1cm]{example-image-b}}
\zoombox{\includegraphics[width=1cm]{example-image-c}}
\zoombox{\includegraphics[height=1cm]{example-image-golden}}
\zoombox{\includegraphics[width=1cm]{example-image-golden-upright}}
\end{frame}
\end{document}
The second example defines pairs of commands for marking opposing corners (lower left & upper right .OR. upper left & lower right) of a zoom box, and commands for marking text sequences/entire paragraphs.
\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\InputIfFileExists{\jobname.zom}{}{}
\newwrite\zoomdat
\immediate\openout\zoomdat=\jobname.zom
\newcommand{\startzoombox}[2][0]{%
\leavevmode%
\pdfsavepos%
\protected@write\zoomdat{}{%
\string\expandafter\string\def\string\csname\space zb#2.ulx\string\endcsname{%
\noexpand\number\pdflastxpos}%
\string\expandafter\string\def\string\csname\space zb#2.uly\string\endcsname{%
\noexpand\number\pdflastypos}%
}%
\ifcsname zb#2.ulx\endcsname\ifcsname zb#2.lrx\endcsname%
\edef\zoomwd{\dimexpr \csname zb#2.lrx\endcsname sp- \csname zb#2.ulx\endcsname sp\relax}%
\edef\zoomdp{\dimexpr \csname zb#2.uly\endcsname sp- \csname zb#2.lry\endcsname sp\relax}%
\pdfdest name {zb#2.in} fitr
width \zoomwd
height 0pt
depth \zoomdp
\immediate\pdfannot
width \zoomwd
height 0pt
depth \zoomdp
{%
/Subtype/Link/H/N
/Border [0 0 1 [1 2]]
/A <<
/S/JavaScript
/JS (
if(typeof(zoomed)=='undefined'||!zoomed){
var lastView=this.viewState;
zoomed=true;
this.gotoNamedDest('zb#2.in');
}else{
this.viewState=lastView;
zoomed=false;
}
)
>>
}%
\fi\fi%
}
\def\stopzoombox#1{%\leavevmode%
\leavevmode%
\pdfsavepos%
\protected@write\zoomdat{}{%
\string\expandafter\string\def\string\csname\space zb#1.lrx\string\endcsname{%
\noexpand\number\pdflastxpos}%
\string\expandafter\string\def\string\csname\space zb#1.lry\string\endcsname{%
\noexpand\number\pdflastypos}%
}%
}
\def\startzoom{%
\stepcounter{@zb@id}%
\xdef\@lblStack{\the@zb@id.\@lblStack}%
\@ifstar\@startzoomstar\@startzoom%
}
\newcommand{\@startzoom}[1][0]{%
\raisebox{\baselineskip}[0pt][0pt]{\startzoombox[#1]{.\the@zb@id}}%
}
\newcommand{\@startzoomstar}[1][0]{%
\makebox[0pt][r]{\raisebox{\baselineskip}[0pt][0pt]{\startzoombox[#1]{.\the@zb@id}}%
\hspace{\parindent}}%
}
\def\stopzoom{%
\@ifstar\@stopzoomstar\@stopzoom%
}
\def\@stopzoom{%
\@popStack\@lblStack%
\raisebox{-1ex}[0pt][0pt]{\stopzoombox{.\@lblCur}}%
\xspace%
}
\def\@stopzoomstar{%
\@popStack\@lblStack%
\hfill\raisebox{-1ex}[0pt][0pt]{\stopzoombox{.\@lblCur}}%
\xspace%
}
\newcounter{@zb@id}
\def\@lblStack{}
\def\@popStack#1{\expandafter\@@popStack#1\nil}
\def\@@popStack#1.#2\nil{\gdef\@lblCur{#1}\gdef\@lblStack{#2}}
\RequirePackage{xspace}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Paragraph zooming}
\startzoom[1]First paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first \startzoom[1]\emph{Do not miss this one.}\stopzoom First paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph first paragraph.\stopzoom*
\startzoom*[1]Second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph second paragraph.\stopzoom*
\end{document}
The two commands for marking the corners of a zoom area are
\startzoombox[line width]{label}
and
\stopzoombox{label}
They are meant to be used in picture-making environments, such as pspicture or tikzpicture. Associated command pairs must be identified by unique labels.
For marking text and paragraphs the following commands have been provided:
\startzoom[lwidth]
\startzoom*[lwidth]
\stopzoom
\stopzoom*
The starred versions insert horizontal space (negative \parindent on first line, \hfill at the end of the paragraph).
Zoom areas may be nested. However, smaller ones should be placed on top of bigger ones (i.e. to appear later in the code), in order not to be obscured.
Note that at least two pdflatex runs are necessary.
EDIT:
A dvipdfmx/XeLaTeX version of the \zoombox macro is given in: How do I include a click-to-zoom thumbnail picture in a non-beamer document?
contentis stored in a\saveboxfirst in order to be measured its dimensions for later sizing the zoom area. Saveboxes are lr-boxes, that is, they behave like\hbox(TeX) or\makebox(LaTeX). In order to get whole paragraphs, you could either put the text in a\parboxorminipage, as you suggested, or use the\startzoombox[line width]{label}\stopzoombox{label}commands to mark opposing corners of the zoom area. – AlexG Mar 01 '11 at 09:53/C [\@linkbordercolor]before/Border ...in the above code. The preamble code between the comment lines must be surrounded by\makeatletterand\makeatotherand don't forget to\usepackage{hyperref}– AlexG Mar 01 '11 at 10:19\hfillbetween the last full stop and\stopzoombox. This pushes the latter to the right text margin. – AlexG Mar 02 '11 at 15:53/C [\@linkbordercolor]to give opacity to the dotted line. – alfC Mar 02 '11 at 21:05\startzoom[lwidth]{label},\startzoom*[lwidth]{label},\stopzoom{label},\stopzoom*{label}. The starred versions insert horizontal space (negative \parindent, \hfill) for marking normal paragraphs. – AlexG Mar 03 '11 at 08:57pdfannotto recover this animation feature when changing zoom levels via zoom boxes? – alfC Apr 09 '13 at 05:30scrollJavaScript method, but instead of centring the given position (the centre coordinates of the zoom-to region) within the viewer window (as advertised by the Acrobat JavaScript specification), it is moved to the upper left corner of the viewer window, only leaving visible the lower right quarter of the zoom-to region, which is clearly not what is expected. – AlexG Sep 12 '13 at 08:36{contents}argument is centred within a tightly fitting zoombox (fitrPDF destination) that has the same aspect ratio as the document page. If thebeamerdocument was set-up with the same aspect ratio as the projector or computer screen (here: 4:3), then in full screen, zoom boxes are enlarged to the maximum, while centred on the screen. Perhaps you have a computer screen with an asp ratio other than 4:3. Try\documenclass[169]{beamer}or whatever. – AlexG Sep 13 '13 at 15:13\section{\zoombox[1]{Title}}and\section{\zoombox[1]{Title\hfill}}but in both cases the zoom box doesn't extend to the end of the line (up to the right margin). Trying to use the\start*-\stop*versions gave an error when trying to use it inside a section. – alfC Apr 11 '15 at 10:15\start/stop-zoombox, it works as long as there is an "alternative title" set for the section.\section[Title Alternate]{\startzoom*[0]{tag1}Title\stopzoom*{tag1}}. I had to add some additional\hspaceto include the section number, so it is still an incomplete hack. – alfC Apr 16 '15 at 06:57\startzoom/\stopzoom. For\startzoombox/\stopzoombox, however, labels remain mandatory, since the commands may be used in[tikz|ps]pictureenvironments, where their placement does not necessarily follow a stack-like fashion. – AlexG Jan 27 '16 at 12:55beamerthen it works fine, but if I change tobook, then I got the errors:! Arithmetic overflow. \calc@next@digit ... \multiply \calc@numerator 10 \calc@Acount \calc@numerat..., any advise? – MadyYuvi Aug 10 '19 at 04:59\begin{frame}and\end{frame}from the document body when usingbook? These are commands frombeamer. – AlexG Aug 10 '19 at 14:31