# How can I make toggle buttons with images using pdflatex?

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:

and the same array with the left button as it would appear in a toggled state is shown 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.

-

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}

-
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