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\PDFFormRadioOrig\PDFForm@Radio
\def\PDFForm@Radio{\PDFFormRadioOrig\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}
\layerCheckBox{Table 1}{table1}{on}~Option~A \quad \layerCheckBox{Table 2}{table2}{off}~Option~B
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=Tables]{Table 1}{table1}{on}%
\begin{tabular}{|c|c|}\hline
\TextField[name=phonenumber1]{Phone:} & 2\\\hline
& \\\hline
& \\\hline
\end{tabular}%
\end{ocg}%
}%
\begin{ocg}[radiobtngrp=Tables]{Table 2}{table2}{off}%
\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}
\layerCheckBox{Table 1}{table1}{on}~Option~A \quad \layerCheckBox{Table 2}{table2}{off}~Option~B
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=Tables]{Table 1}{table1}{on}%
\begin{tabular}{|c|c|}\hline
Phone: \textField[\rawPDF{\insertOC}]{phonenumber1}{2.51cm}{2.2ex} & 2 \\\hline
& \\\hline
& \\\hline
\end{tabular}%
\end{ocg}%
}%
\begin{ocg}[radiobtngrp=Tables]{Table 2}{table2}{off}%
\begin{tabular}{|c|c|}\hline
1 & 2\\\hline
& \\\hline
\end{tabular}%
\end{ocg}%
\end{document}
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.
beamer
tag correct here?