# TextField and animateinline

I have a \ChoiceMenu with two options and based on this selection I want to display one frame out of two. If I use a \TextField in the frames I get this error "error (ext4): link annotations cannot be inside an XForm".

Is there a way to solve this Problem or is there a better solution to realise this?

\documentclass[11pt,a4paper]{article} % Use A4 paper with a 11pt font size article
\usepackage{eforms}
\usepackage{animate}
\usepackage{pgfplots} %Required for graph
%“running in backwards compatibility mode” Compiler Warning

\begin{document}
\begin{Form}

\begin{center}
\begin{NoHyper}
\begin{animateinline}[nomouse,step,label=Tables]{0}
\begin{tabular}{|c|c|}\hline
\TextField[name=phonenumber1]{Phone:} &{\color{white}2} \\\hline
& \\\hline
& \\\hline
\end{tabular}

\newframe%
%\TextField[name=phonenumber2]{Phone:} \TextField[name=phonenumber,maxlen=10]{Phone2:}
\begin{tabular}{|c|c|}\hline
1 & 2\\\hline
& \\\hline
\end{tabular}

\end{animateinline}
\end{NoHyper}
\end{center}

\end{Form}
\end{document}

• is the beamer tag correct here? Jan 7, 2016 at 14:36
• Crosspost Jan 8, 2016 at 10:18

animate compiles the graphical content of animation frames into so called "Form XObjects", or "XForms" in short, that can be referenced later. However, this is not possible for PDF annotations (interactive elements) due to limitations of the PDF format.

But we can use OCGs, aka PDF Layers, to make text, graphics as well as PDF annotations (text fields, in the present case) optional.

ocgx2 provides the command \ocgxii@insert@OC which inserts the raw PDF code to make PDF annotations layer-aware. In the example below, we make use of \ocgxii@insert@OC to patch all hyperref's Form producing commands.

The Form producing commands of the eforms package are a good alternative, because they allow the insertion of raw PDF code ( thanks to the \rawPDF{...} macro) in order to fine-tune the behaviour of form elements. See the second code box.

The example generates (by means of \begin{ocg}...\end{ocg}) two layers, table1 and table2, which belong to a common radio button group Tables, such that only one of them can be enabled at a time.

Example using hyperref package:

\documentclass[11pt,a4paper]{article}

\usepackage{hyperref} % \TextField etc.

\usepackage{ocgx2}  % PDF Layers

\makeatletter
% patch hyperref's Form producing commands to make them layer-aware
\let\PDFFormCheckOrig\PDFForm@Check
\def\PDFForm@Check{\PDFFormCheckOrig\ocgxii@insert@OC}
\let\PDFFormPushOrig\PDFForm@Push
\def\PDFForm@Push{\PDFFormPushOrig\ocgxii@insert@OC}
\let\PDFFormListOrig\PDFForm@List
\def\PDFForm@List{\PDFFormListOrig\ocgxii@insert@OC}
\let\PDFFormTextOrig\PDFForm@Text
\def\PDFForm@Text{\PDFFormTextOrig\ocgxii@insert@OC}
\let\PDFFormSubmitOrig\PDFForm@Submit
\def\PDFForm@Submit{\PDFFormSubmitOrig\ocgxii@insert@OC}
\let\PDFFormResetOrig\PDFForm@Reset
\def\PDFForm@Reset{\PDFFormResetOrig\ocgxii@insert@OC}
\makeatother

%alternative check box command for layer switching
\newcommand\layerCheckBox[3]{%
% #1: layer name (as shown in Layers tab), #2: layer id,
% #3: initial visibility
\resizebox{1.44ex}{!}{%
\makebox[0pt][l]{\showocg{#2}{$\circ$}}%
\begin{ocg}{#1}{#2}{#3}$\bullet$\end{ocg}%
}%
}
\usepackage{graphics} % \resizebox

\begin{document}
\begin{Form}

\makebox[0pt][l]{%
\begin{tabular}{|c|c|}\hline
\TextField[name=phonenumber1]{Phone:} & 2\\\hline
& \\\hline
& \\\hline
\end{tabular}%
\end{ocg}%
}%
\begin{tabular}{|c|c|}\hline
1 & 2\\\hline
& \\\hline
\end{tabular}%
\end{ocg}%

\end{Form}
\end{document}


Using eforms package:

\documentclass[11pt,a4paper]{article}

\usepackage{eforms} % \textField

\usepackage{ocgx2}  % PDF layers

\makeatletter
%inserts raw PDF code to make annotations layer-aware
\let\insertOC\ocgxii@insert@OC
\makeatother

\usepackage{graphics} % \resizebox

% layer switching command based on \showocg from ocgx2; used instead of \ChoiceKey
\newcommand\layerCheckBox[3]{%
% #1: layer name (as shown in Layers tab), #2: layer id, #3: initial visibility
\resizebox{1.44ex}{!}{%
\makebox[0pt][l]{\showocg{#2}{$\circ$}}%
\begin{ocg}{#1}{#2}{#3}$\bullet$\end{ocg}%
}%
}

\begin{document}

\makebox[0pt][l]{%
\begin{tabular}{|c|c|}\hline
Phone: \textField[\rawPDF{\insertOC}]{phonenumber1}{2.51cm}{2.2ex} & 2 \\\hline
& \\\hline
& \\\hline
\end{tabular}%
\end{ocg}%
}%

Unfortunately, eforms is not part of TeX-Live and must be installed manually by downloading eforms.dtx, eforms.ins, insdljs.dtx, insdljs.ins into the current directory and running latex on the *.ins files.