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.


1 Answer 1


This can be done without JavaScript using PDF Layers (OCGs):

(stateA.png) (stateB.png)




\switchocg{imgA imgB}{%
    \begin{ocg}{Image A}{imgA}{on}
  \begin{ocg}{Image B}{imgB}{off}

  • 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. Jul 23, 2013 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .