Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am currently designing an interactive PDF by means of the media9 package in Latex.

I have three \mediabutton buttons that I would like to treat as toggle buttons. A picture of the buttons is shown here:

enter image description here

and the same array with the left button as it would appear in a toggled state is shown here:

enter image description here

Now, each \mediabutton is already associated with three images:

  1. an image to display when there is no interaction with the button,
  2. an image to display when the user clicks on the button.
  3. an image to display when the mouse hovers over the button,

All I want to do is to swap the images 1 & 3 for a button that is toggled.


As I understand, these images are attached to the button as Icon objects. The PDF Javascript API states that button icons can be retrieved using the buttonGetIcon method whilst they can be set using the buttonSetIcon method.

I tried doing this using code such as the following:

var button = this.getField("mbtn@0");
var normal_icon = button.buttonGetIcon(0);
var hover_icon = button.buttonGetIcon(2);

button.buttonSetIcon(hover_icon, 0);
button.buttonSetIcon(normal_icon, 1);

This just causes the button in question to disappear (or rather, it seems to lose all its images thereby appearing to be invisible).


I have tried to embed images in the PDF that I then tried to convert to Icon objects that could be attached to buttons. There appears to be no straightforward method for performing this translation though.


I would be very grateful for any pointers in how I could do this. Manual methods are not an option as our software produces reports automatically.

Thank you in advance.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The PDF-spec doesn't allow for push buttons (like the ones produced with \mediabutton from media9) to persistently toggle between two states.

If the two states On and Off are enough for you, you could try to simulate it with the animate package. The \framebox commands should be replaced with two \includegraphics{...}:

\documentclass{article}
\usepackage{animate}

\begin{document}

\begin{animateinline}[step]{1}
  \framebox[1in][c]{Off}
\newframe
  \framebox[1in][c]{On}
\end{animateinline}

\end{document}
share|improve this answer
    
I ended up making two buttons that are stacked atop one another. I then set the visible property to toggle between them. I'm accepting your answer since you got me thinking in simpler terms about the problem that ultimately led to the solution. Thanks. –  Winterstream Jul 23 '13 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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