2

I'm trying to create beamer slides with an embedded animation using animate that works well with static pdf viewers and Acrobat Reader.

The basic issue is that the last frame of the animation is the key one with the earlier frames showing how that frame is developed. So, I want static viewers to be able to see the key final frame but I don't want to give away the ending when viewing dynamically.

My intuition was that I could achieve this by setting poster=last and then use autoplay (and maybe pausing in a timeline to hold it on frame 1) to start at frame 1 in Acrobat. That works for static browsers, but what happens in Acrobat is that the last frame is shown but the animation needs to be activated by mouse click to return to the first frame and set the animation going.

A working example to demonstrate (not using beamer but displaying the same behaviour):

\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{animateinline}[controls, autoplay, poster=last]{2}  
\multiframe{7}{n=0+30}{
  \begin{tikzpicture}
    \useasboundingbox (0,0) rectangle (4,8);
    \node [draw, circle] (A) at (2,2){A};
    \node [draw, circle] (B) [above=4cm of A] {B};
    \draw [->, thick] (A) to[out=\n, in=\n] (B);
  \end{tikzpicture}    
}
\end{animateinline}
\end{document}

What I'd like to set up is:

  1. When opened in static viewers, the final frame is shown with the arrow on the left, so that people can see how the animation ends.
  2. However, when opened in Reader, so that the animation will run, the arrow is seen on the right (frame 1).

Any suggestions?

0

This can be achieved using OCGs (optional content groups, aka PDF Layers) and a bit of JavaScript.

We repeat the last frame, but create two versions of it, each associated with a PDF Layer. One Layer shows the (real) last frame and is ON by default, the other showing the first frame is OFF by default. In AR, the latter is switched ON and the former OFF using JavaScript during the Page-Open event.

The already existing OCGs acro and other can safely be reused (reopened) in other animations within the document.

\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{ocgx}
%\usepackage{fixocgx}

\pdfpageattr{/AA << %additional actions for pageopen event
  /O << /S/JavaScript /JS (
    var ocgArray = this.getOCGs();
    for (var i=0; i < ocgArray.length; i++) {
       if (ocgArray[i].name == "other") ocgArray[i].state = false;
       if (ocgArray[i].name == "acro") ocgArray[i].state = true;
    }
  ) >>
>>}

\begin{document}

Bla, bla.

\newpage

\begin{animateinline}[
  controls,
  poster=last
]{2}  
\multiframe{7}{n=0+30}{
  \begin{tikzpicture}
    \useasboundingbox (0,0) rectangle (4,8);
    \node [draw, circle] (A) at (2,2){A};
    \node [draw, circle] (B) [above=4cm of A] {B};
    \draw [->, thick] (A) to[out=\n, in=\n] (B);
  \end{tikzpicture}
}
\newframe* % During playback, pause before this frame.
  \begin{tikzpicture}
    \useasboundingbox (0,0) rectangle (4,8);
    \node [draw, circle] (A) at (2,2){A};
    \node [draw, circle] (B) [above=4cm of A] {B};
    \begin{ocg}{acro}{acro}{0}% default = not visible
      \draw [->, thick] (A) to[out=0, in=0] (B);
    \end{ocg}
    \begin{ocg}{other}{other}{1}% default = visible
      \draw [->, thick] (A) to[out=180, in=180] (B);
    \end{ocg}
  \end{tikzpicture}
\end{animateinline}
\end{document}
3
  • I used a MWE that didn't require links to external files, but some of the animations link to pre-generated multipage PDF files containing frames (I'm using R and knitr). Is it possible to load frames into an OCG from within animategraphics rather than animateinline?
    – David_O
    Feb 5 '15 at 16:59
  • @user3401916 Not without changing code within animate.sty. Alternatively you could make use of \includegraphics{...} inside the animateinline environment.
    – AlexG
    Feb 6 '15 at 7:46
  • @user3401916 Also see tex.stackexchange.com/a/86671, if the external files have zero-padded numbers and you want to have them animated using \includegraphics inside animateinline.
    – AlexG
    Feb 6 '15 at 9:20

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.