8

(This is an end-of-year crazy question)

Is it possible to embed a (scrollable) frame or a PDF inside a PDF? If so, how to do it in (pdf)LaTeX?

This is something pretty common in HTML (see for example http://www.echoecho.com/htmlframes01.htm). Here it is a webpage with PDF frames https://www.cs.tut.fi/~jkorpela/html/iframe-pdf.html

Here it is a fake screenshot so you get the idea.

Portable and non-portable (e.g. only-Acrobat) answers are welcomed. fakeframe


Example of a down arrow below a frame. The up arrow can be on top of the frame and the triangles point up.

downarrow

  • Related but not the same thing: tex.stackexchange.com/q/96260/1871 – alfC Dec 17 '15 at 12:23
  • 3
    As far as I can see, the only "off the shelf" scrollable element would be a multiline text field. However, to make it scrollable, you can not make it read-only. Another possbility would be placing a button field, and make the scrollable PDF the icon. You then add scrolling buttons and appropriate JavaScript code to change the position of the icon in the field (see button field properties in Acrobat). – Max Wyss Dec 17 '15 at 12:25
  • 2
    The closest to your requirements that you can get is probably this: tex.stackexchange.com/a/211010 – AlexG Dec 17 '15 at 12:29
12

Vertical scrolling based on the animate package; definition of command \smoothScroll taken from an earlier post with slight modifications.

As an example document, we take lppl.pdf from TEXMF/doc/latex/base/lppl.pdf, the pages somewhat trimmed.

Update with suggestions incorporated:


Start auto-scroll by clicking on the "widget", pause auto-scroll on mouse-down in the "widget" (and moving the mouse out, while keeping it pressed).

The buttons above and below the "widget" step through the document on mouse click.

[Shift]+click on the buttons rewinds to the top or jumps to the bottom of the document.


Adobe Reader required. Open on ↗ShareLaTeX.

enter image description here

\documentclass[a5paper]{scrartcl}

\usepackage{multido}
\usepackage{graphicx}
\usepackage{MnSymbol} % \triangle, \triangledown
\usepackage{animate}
\usepackage{media9}   % \mediabutton
\usepackage{xsavebox} % \xsbox{<xsbox id>}{<content>} , \the<xsbox id>

%%%%%%% docToBox  %%%%%%%%
\newcommand\docToBox[3]{%
  % #1 <file name (PDF)>
  % #2 <left> <bot> <right> <top> % trim pages by given amounts (PS points)
  % #3 <boxnum>
  \pdfximage{#1}%  just for counting pages
  \multido{\i=1+1}{\pdflastximagepages}{%
    \global\setbox#3=\vbox{%
      \box#3%
      \hbox to \textwidth{\includegraphics[page=\i,trim=#2,clip,width=\textwidth]{#1}}%
    }%
  }%  
}
%%%%%%% /docToBox %%%%%%%%

%%%%%%% smoothScroll %%%%%
\newcommand\smoothScroll[5][]{%
  % [#1] autoplay, controls, ... (see: texdoc animate)
  % #2 <boxnum>
  % #3 <viewport height>
  % #4 <steps>
  % #5 <steps per sec> while playing; >25 doesn't make sense
  \edef\mywd{\the\wd#2}%
  \edef\myht{\the\ht#2}%
  \edef\mytht{\the\dimexpr\ht#2+\dp#2\relax}%
  \xsbox{XFormOfDoc}{\usebox{#2}}% distill box into re-usable PDF XObject
  \edef\portht{\the\dimexpr#3\relax}%
  \begin{animateinline}[#1,width=\mywd,height=\portht]{#5}%
    \multiframe{#4}{
      dRaiseLen=\the\dimexpr-\myht+\portht\relax+\the\dimexpr(\mytht-\portht)/#4\relax
    }{%
      \begin{minipage}[b][\portht][b]{\mywd}%
        \raisebox{\dRaiseLen}[0pt][0pt]{\theXFormOfDoc}%
      \end{minipage}%
    }%
  \end{animateinline}%
}
%%%%%%% /smoothScroll %%%%%

\begin{document}\Huge

\newbox\lipsumbox
%load the document with trims into save-box
\docToBox{lppl.pdf}{131 110 115 121}{\lipsumbox}
\edef\boxwidth{\the\wd\lipsumbox}% 

\noindent Before you consider using \LaTeX, read the fine-print:\\
\noindent\mediabutton[
  jsaction={
    if(event.shift){anim.lppl.pause();anim.lppl.frameNum=0;}
    else try{anim.lppl.frameNum--}catch(e){}
  }
]{\fboxsep=0pt\framebox[\boxwidth][c]{\tiny\strut$\triangle\triangle\triangle$}}
%the scrolling widget
\noindent{\fboxsep=-\fboxrule\fbox{\smoothScroll[label=lppl]{\lipsumbox}{0.79\textheight}{512}{25}}}
\vskip -0.8\baselineskip
\noindent\mediabutton[
  jsaction={
    if(event.shift){anim.lppl.pause();anim.lppl.frameNum=anim.lppl.numFrames-1;}
    else try{anim.lppl.frameNum++}catch(e){}
  }
]{\fboxsep=0pt\framebox[\boxwidth][c]{\tiny\strut$\triangledown\triangledown\triangledown$}}%

\end{document}
  • This is very cool, can the animate controls be used a scroll control? – alfC Dec 17 '15 at 20:08
  • 1
    They can already be used as such, e.g. "<" and ">" for stepping. A slider doesn't seem possible to implement, though. – AlexG Dec 18 '15 at 8:24
  • Yes, I mean if the buttons can be arranged vertical and on the side. Or perhaps have a short elongated button below the frame [ vvv ] and one on the top [ ^^^ ]. See my edit at end of the post for an example image. – alfC Dec 18 '15 at 9:21
  • 1
    @alfC In order to pause it, press the mouse button over the frame and keep it pressed while moving the mouse pointer out (as written in the answer). – AlexG Jul 25 '16 at 7:20
  • 1
    @alfC Although a bit un-orthodox, this way of pausing/resuming an animation by mouse-down/mouse-up was designed on purpose. Because one has better control over the playing state, while giving explanations during a lecture, for instance. You can be sure that the animation freezes when your finger presses the button. With a conventional click (press-release) to both stop and resume an animation, you can never be sure whether you end up with a paused animation or with one that runs away, especially when clicking in rapid succession. (The same behaviour was also programmed into VPlayer.swf, btw.) – AlexG Jul 29 '16 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.