Is it easy to make a PDF document containing forms in LaTeX? I tried to use TextFields but a friend of mine said that it won't work on every operating system PDF readers?
-
Would http://www.acrotex.net/ help? – pluton Jul 06 '14 at 19:35
-
1I haven't done this myself but the hyperref package seems to have everything that you would need. – Jul 06 '14 at 21:14
-
Please have a look for example on this recent question (although it does not work in that case for some unknown reason on Windows): http://tex.stackexchange.com/questions/187767/no-checked-checkbox-on-hyperref-package/187850#187850 – Jul 06 '14 at 21:39
-
@ChristianHupfer Thanks but in my case the document should work on Linux, Windows and Mac. – novice Jul 06 '14 at 21:49
-
@novice: Well, the form works nevertheless, but on Windows, due to some reasons, the checkboxes are not checked initally. If you do not need such an prechecked box, there is no problem at all – Jul 06 '14 at 21:52
-
Which elements do you need to go into the form and in what context? If you post a minimal working example (MWE) indicating the appropriate context and what you need, it would be much easier to either answer your question or explain why it cannot be done in a cross-platform way. I've definitely created single and multiline text boxes, radio buttons and drop-down menus for PDFs which work on all three platforms. At least, they work on three in Adobe's reader. (They do not work in all PDF viewers.) Checkboxes are more problematic. – cfr Jul 06 '14 at 22:11
-
I have a picture of the document on my mind but I don't know if I can download it. Basically there is a rectangular area where 23 editable forms and 5 non-editable areas containing captions of the forms. – novice Jul 07 '14 at 06:37
1 Answers
In the future, please note that all questions should include an MWE. You are likely to get more useful help if you provide one, as well as increasing the number of people willing to provide that help.
In this case, I provide a simple example of a form which includes multiline text fields and choice menus. Some of the former have default text and others do not. The latter use drop-down boxes allowing the user to choose one of three possibilities for each item. A uniform default is set for each set of items.
Note that the form will not look precisely the same in all PDF viewers and that some PDF viewers will not support form fields at all.
Note, too, that Adobe Reader will not allow users to save the filled form. Plenty of other viewers (e.g. Okular) will do, however.
A First Attempt
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\pagestyle{empty}
\begin{Form}
\centering
\TextField[charsize={10pt},multiline=true,height={60mm},width={100mm},name={textfield1},bordercolor={1 1 1}]{First, a simple text field with no default text:\\
}
\vskip 5pt
\begin{minipage}[b]{.35\textwidth}
Usage of \verb|\ChoiceMenu|:
\begin{itemize}
\item aspect 1 \hspace*{\fill}\ChoiceMenu[name=aspect1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 2 \hspace*{\fill}\ChoiceMenu[name=aspect2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 3 \hspace*{\fill}\ChoiceMenu[name=aspect3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 4 \hspace*{\fill}\ChoiceMenu[name=aspect4,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 5 \hspace*{\fill}\ChoiceMenu[name=aspect5,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 6 \hspace*{\fill}\ChoiceMenu[name=aspect6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 7 \hspace*{\fill}\ChoiceMenu[name=aspect7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={moreaspects},bordercolor={0.2 0.2 0.7},default={additional aspects}]{\mbox{}
}
\end{minipage}
\hfill
\begin{minipage}[b]{.55\textwidth}
Note that \verb|name|s must be unique:
\begin{itemize}
\item possession of feature 1 \hspace*{\fill}\ChoiceMenu[name=feature1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 2 \hspace*{\fill}\ChoiceMenu[name=feature2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 3 \hspace*{\fill}\ChoiceMenu[name=feature3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 4 \hspace*{\fill}\ChoiceMenu[name=feature4,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 5 \hspace*{\fill}\ChoiceMenu[name=feature5,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 6 \hspace*{\fill}\ChoiceMenu[name=feature6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 7 \hspace*{\fill}\ChoiceMenu[name=feature7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={morefeats},bordercolor={0.2 0.2 0.7},default={possession of additional features}]{\mbox{}
}
\end{minipage}
\end{Form}
\end{document}
Here is the form filled out in Okular with form fields shown:

Correcting the Code
The above is pretty good except that our choice menus do not show the first (default) item in the list when form fields are not active (or, apparently, when you copy the contents as a png to post here). So it would be better to have the first item be a blank/neutral setting with the first of the three possibilities given as the second item in the menu:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\pagestyle{empty}
\begin{Form}
\centering
\TextField[charsize={10pt},multiline=true,height={60mm},width={100mm},name={textfield1},bordercolor={1 1 1}]{First, a simple text field with no default text:\\
}
\vskip 5pt
\begin{minipage}[b]{.35\textwidth}
Usage of \verb|\ChoiceMenu|:
\begin{itemize}
\item aspect 1 \hspace*{\fill}\ChoiceMenu[name=aspect1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 2 \hspace*{\fill}\ChoiceMenu[name=aspect2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 3 \hspace*{\fill}\ChoiceMenu[name=aspect3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 4 \hspace*{\fill}\ChoiceMenu[name=aspect4,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 5 \hspace*{\fill}\ChoiceMenu[name=aspect5,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 6 \hspace*{\fill}\ChoiceMenu[name=aspect6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 7 \hspace*{\fill}\ChoiceMenu[name=aspect7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={moreaspects},bordercolor={0.2 0.2 0.7},default={additional aspects}]{\mbox{}
}
\end{minipage}
\hfill
\begin{minipage}[b]{.55\textwidth}
Note that \verb|name|s must be unique:
\begin{itemize}
\item possession of feature 1 \hspace*{\fill}\ChoiceMenu[name=feature1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 2 \hspace*{\fill}\ChoiceMenu[name=feature2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 3 \hspace*{\fill}\ChoiceMenu[name=feature3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 4 \hspace*{\fill}\ChoiceMenu[name=feature4,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 5 \hspace*{\fill}\ChoiceMenu[name=feature5,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 6 \hspace*{\fill}\ChoiceMenu[name=feature6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 7 \hspace*{\fill}\ChoiceMenu[name=feature7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={morefeats},bordercolor={0.2 0.2 0.7},default={possession of additional features}]{\mbox{}
}
\end{minipage}
\end{Form}
\end{document}

- 198,882
-
I know this is very old and very very late, but I figured I'd ask here a quick one. Would you happen to know how to get the value of the section, if one does calculations? Or more precisely, if clauses based on content for a text field? – Zelos Malum Oct 08 '17 at 06:52
-
@ZelosMalum I suggest asking a new question, linking this answer if it is relevant. I've only used this for simple cases i.e. text input. The most complicated thing I tried successfully added radio buttons. Calculations are a whole new ball game ;). – cfr Oct 09 '17 at 09:19