10

Is there a way in beamer to have some kind of dynamic picture that will change if the mouse is moved over it or if the button is clicked?

  • 2
    Related : http://tex.stackexchange.com/questions/65096/how-to-make-a-diagram-composed-of-superimposed-layers-where-the-viewer-can-make – percusse Nov 07 '12 at 21:04
  • Very interesting link, but this kind of solution needs javascript programming :-( And should only solve my second case (button clicked)... – Lionel MANSUY Nov 07 '12 at 21:20
  • 2
    Unfortunately, Javascript is seemingly the only way to achieve satisfactory interaction. (even worse only with AcroRead) – percusse Nov 07 '12 at 21:44
  • you can simply use \inlcudegraphics<1>{...} what should be on overlay <1> and so on. –  Nov 08 '12 at 08:10
  • 1
    animate package? – AlexG Nov 08 '12 at 09:03
  • @Herbert No, this will not solve my cases: this will only make a predetermined animation; the above suggestion fit better – Lionel MANSUY Nov 08 '12 at 09:29
  • @AlexG 'animate' package will not do the job, but I will try to understand how the command buttons are made – Lionel MANSUY Nov 08 '12 at 09:48

1 Answers1

11

Here is a straightforward solution using a Widget Annotation (Push Button) according to the PDF specification. It displays different pictures depending on the current mouse position and its button state (out, roll-over, button-down).

\documentclass{article}
\usepackage{mwe}

\newsavebox\imga
\newsavebox\imgb
\newsavebox\imgc
\sbox\imga{\includegraphics{example-image-a}}
\sbox\imgb{\includegraphics{example-image-b}}
\sbox\imgc{\includegraphics{example-image-c}}
\edef\imgwd{\the\wd\imga}
\edef\imght{\the\ht\imga}

\immediate\pdfxform\imga
\edef\normalappearance{\the\pdflastxform\space 0 R}
\immediate\pdfxform\imgb
\edef\overappearance{\the\pdflastxform\space 0 R}
\immediate\pdfxform\imgc
\edef\downappearance{\the\pdflastxform\space 0 R}

\begin{document}

\hbox to \imgwd{\vbox to \imght{\vss%
  \pdfannot width \imgwd height \imght depth 0pt {
    /Subtype/Widget
    /F 4
    /FT/Btn/Ff 65536
    /T (my dynamic image) % Widget name; must be unique
    /H/P
    /AP <<
      /N \normalappearance
      /R \overappearance
      /D \downappearance
    >>
  }%
}\hss}

\end{document}

In case of multiple Widget annotations, the Widget's names, as specified by the /T (...) entry, must be uniqe.

enter image description here

AlexG
  • 54,894
  • How did you created the GIF above? – kiss my armpit Nov 09 '12 at 08:04
  • 2
    Recording with ffmpeg, Gif optimization with gifsicle. – AlexG Nov 09 '12 at 08:19
  • 2
    For those who are interested, the method for producing the window recording is given here. – AlexG Nov 09 '12 at 09:34
  • @AlexG I'm in trouble with your code: it works nicely only for the first occurrence of a picture, not for the following ones... I've tried to replace the \Widget subtype by a \Link, but it does not work – Lionel MANSUY Jan 08 '13 at 16:53
  • @LionelMANSUY : The PDF created from the code example works properly only in Adobe Reader (as demonstrated by the animated screen recording). – AlexG Jan 09 '13 at 07:19
  • @AlexG Have you tried to put 2 or 3 of different animated picture on a page? In acrobat, only the first one is shown, in the previewer of Texmaker or in Foxit reader, they are all shown, but inactive... I'm suspected the need to create a AcroForm to correctly use a \FT\Btn – Lionel MANSUY Jan 09 '13 at 07:35
  • @LionelMANSUY Adding an /AcroForm entry to the PDF catalog is not required here. Just make sure that the Widget's names, that is, the /T (...) entries in the Widget annotation dictionary, are unique per annotation. – AlexG Jan 09 '13 at 08:47
  • @AlexG Thank you very much, you save my life :-) ! I've tried many things, but not this entry – Lionel MANSUY Jan 09 '13 at 09:36