# \pushbuttons with Icons with pdflatex (xobject reference)

I would like to create a pushbutton with icons instead of text. Like the text in the example below the icons should change with the mouse options.

The manual of the eforms package (eformman.pdf) mentions options \I, \RI and \IX

  \I: (push buttons only) an indirect reference to a form XObject
defining the buttons’s normal icon


There is an example on http://www.math.uakron.edu/~dpstory/webeq_ex.html (eqforms.tex) but only for the dvips route. Is it possible to use icons with pdflatex too? And how do I create and reference the xobject? (I tried various variants with \pdfxform etc but to no avail).

(A solution which use javascript code would be fine too)

\documentclass{article}
\usepackage[pdftex]{eforms}
\usepackage{graphicx}
\begin{document}
\pushButton[\CA{Push}\AC{Me}\RC{Reset}\A{/S/ResetForm}]
{myButton}{30bp}{15bp}
\end{document}


## Edit

Due to the help of @AlexG I found out why the "natural" command \I, \XI and \RI didn't work: The relevant code in eforms.sty uses braces in the /I entry which imho doesn't work with pdftex. If I change the code everything works fine (I moved the 0 R to the internal code):

\documentclass{article}
\usepackage[pdftex]{eforms}
\usepackage{graphics}
\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}}
\immediate\pdfxform\imga
\edef\normalappearance{\the\pdflastxform}
\immediate\pdfxform\imgb
\edef\overappearance{\the\pdflastxform}
\immediate\pdfxform\imgc
\edef\downappearance{\the\pdflastxform}

\pdfcompresslevel0
\pdfobjcompresslevel0
\begin{document}
\makeatletter
\def\@eqI#1{\ifx\annot@type\annot@type@button
\def\eq@arg{#1}\ifx\eq@arg\@empty
\let\eq@I\@empty\else\def\eq@I{/I #1\space 0 R}% removed brace around #1,
\eq@define@IconMK\fi\fi}

\def\@eqRI#1{\ifx\annot@type\annot@type@button
\def\eq@arg{#1}\ifx\eq@arg\@empty
\let\eq@RI\@empty\else\def\eq@RI{/RI #1\space 0 R}% removed brace around #1 ..
\eq@define@IconMK\fi\fi}

\def\@eqIX#1{\ifx\annot@type\annot@type@button
\def\eq@arg{#1}\ifx\eq@arg\@empty
\let\eq@IX\@empty\else\def\eq@IX{/IX #1\space 0 R}% removed brace around #1 ..
\eq@define@IconMK\fi\fi}
\makeatother

\pushButton[
\TP{1}
\I{\normalappearance}
\RI{\overappearance}
\IX{\downappearance}
]{myButton2}{100bp}{100bp}
\end{document}


## Edit 2

I have notified the author and he will change the code of eforms.sty so that \I etc works with pdflatex too.

\documentclass{article}
\usepackage[pdftex]{eforms}
\usepackage{graphicx}
\usepackage{mwe}

\newsavebox\img

\sbox\img{\includegraphics{example-image-a}}
\immediate\pdfxform\img
\edef\normalappearance{\the\pdflastxform\space 0 R}

\sbox\img{\includegraphics{example-image-b}}
\immediate\pdfxform\img
\edef\overappearance{\the\pdflastxform\space 0 R}

\sbox\img{\includegraphics{example-image-c}}
\immediate\pdfxform\img
\edef\downappearance{\the\pdflastxform\space 0 R}

\begin{document}

\pushButton[
\mkIns{
/TP 1 /IF<</S/A/FB true/A [0.0 0.0]>>
/I \normalappearance
/RI \overappearance
/IX \downappearance%
}
\A{/S/ResetForm}
]{myButton}{30bp}{22.5bp}

\end{document}

• Perfect. I would never had thought to use \AP (and I would have got the syntax right anyway). But the \A{/S/ResetForm} seems to be a bit dangerous: When I add a second button and then click on the first, then the first shows an empty frame and the second disappears. Can I add something to the buttons so that Resetform resets both to the "normalappearance" graphic? – Ulrike Fischer Jul 18 '13 at 8:13
• @UlrikeFischer I replaced the appearance dict (/AP <<...>>) with the appearance characteristics dict (/MK <<...>>). Maybe a better solution. Note that button names, here myButton, must be unique. – AlexG Jul 18 '13 at 8:43
• That works better (and the eform docu seems to be misleading, it says that about \MK "this key is available only for check boxes and radio buttons.". And I start to understand the connection between the commands and the pdf syntax. I think I will have to read a bit in the pdf reference. – Ulrike Fischer Jul 18 '13 at 8:55
• @UlrikeFischer. Moreover, eform's \MK{...} key doesn't seem to work as advertised. That is why I used \rawPDF{...} instead. – AlexG Jul 18 '13 at 8:59
• I looked up the code in eforms.tex. Instead of \MK you have to use \mkIns{..} in \pushbutton. And actually it looks as if \I{\normalappearance} should work too but I haven't yet find out why it doesn't ;-(. – Ulrike Fischer Jul 18 '13 at 9:33