3

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 acrotex.net help? – pluton Jul 6 '14 at 19:35
  • 1
    I haven't done this myself but the hyperref package seems to have everything that you would need. – Andrew Jul 6 '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): tex.stackexchange.com/questions/187767/… – user31729 Jul 6 '14 at 21:39
  • @ChristianHupfer Thanks but in my case the document should work on Linux, Windows and Mac. – novice Jul 6 '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 – user31729 Jul 6 '14 at 21:52
5

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:

Form in Okular

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}

Corrected form in Okular

  • 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 8 '17 at 6: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 9 '17 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.