7

The code below implements a simple PDF form. Some PDF readers can save the form after it has been filled to a PDF with the new state. This works for the text entry whose entry is saved but the state of any checkbox is lost. Any remedy?

\documentclass{minimal}
\usepackage[pdftex]{hyperref}

\begin{document}
\begin{Form}
    \noindent
    \CheckBox[bordercolor={0 0 0},height=1ex,width=1.5ex,name=yes]{Yes}\quad
    \CheckBox[bordercolor={0 0 0},height=1ex,width=1.5ex,name=no]{No}\quad
    \TextField[name=textfield,width=3cm]{Text:}
\end{Form}
\end{document}

I noted on Mac OS X in the Preview.app that checking a check box alone does not lead the document to be considered as modified. Only entering text leads to a modified state and subsequently only a modified document can be saved. What is special about check boxes?

Maybe this is a reader issue and I would be interested to hear if the example above indeed works. There is a similar question How to get radio boxes right in PDF forms using hyperref? which was closed as off topic.

Edit: I have added name fields for the check boxes. On OS X with Preview.app this still does not solve the problem for me.

  • 1
    They seem to be working with Adobe Pro on Windows 7, although it came up with ...fixing form fields when it loaded the document. You also need to add names for the checkboxes. Any processing must be done with JavaScript. – yannisl Jan 21 '12 at 11:22

1 Answers1

5

PDF forms are very similar to HTML forms. You need to add "name" for the CheckBoxes. this worked, when I tested it with Acrobat Pro.

enter image description here

\documentclass{minimal}
\usepackage[pdftex]{hyperref}
\begin{document}
\begin{Form}
    \noindent
    \CheckBox[bordercolor={0 0 0},height=1ex,width=1.5ex, name=ch1]{Yes}\quad
    \CheckBox[bordercolor={0 0 0},height=1ex,width=1.5ex, name=ch2]{No}\quad
    \TextField[name=textfield,width=3cm,value=default]{Text:}
\end{Form}
\end{document}

Any further processing must be done with JaVaScript. A good bundle of packages is provided by acrotex. The insdljs package provided by acrotex can be very useful for producing forms.

yannisl
  • 117,160
  • Adding the name field does not solve the problem with Preview.app on OSX for me but I can see that not having names is a problem. – Christian Lindig Jan 21 '12 at 11:35
  • @ChristianLindig I am not familiar with OSX pdf readers, but at a stage forms could only be saved with Acrobat Pro and enabled for other Readers only via the Acrobat Pro user. Try this http://tex.stackexchange.com/questions/7869/how-do-you-say-happy-new-year-with-latex to see if you can view it properly. – yannisl Jan 21 '12 at 11:38
  • The document you linked to requires many packages that I am too reluctant to install just for this purpose. For now I am hoping that someone will take a look into the generated PDF to see how the problem manifests itself. – Christian Lindig Jan 21 '12 at 12:23
  • 2
    @ChristianLindig That's fine in the meantime you can open the pdf file with a TeX editor and post the code at about /Type /XObject /Subtype /Form /BBox [0 0 36.496 13.693] /FormType 1 it might help others to come with a better answer. – yannisl Jan 21 '12 at 12:28
  • I'd post the PDF code but it includes binary streams. Is there a way to force PDFLaTeX to generate more readable output? Option -8bit is not enough. – Christian Lindig Jan 21 '12 at 13:13
  • @ChristianLindig Some of the binaries on the top are arbitary characters to allow legacy file transfer programs know that the file is binary. The ASCII part is of interest only, from where it says /FORM. – yannisl Jan 21 '12 at 13:48
  • @YiannisLazarides It is not true that forms could be enabled for saving in non-Acrobat Pro readers only by using Acrobat Pro. The point was/is, they can be saved only in Adobe Reader if this is enabled in Acrobat Pro. Whether other PDF software could/can fill and save forms is a matter of the capabilities of that software. The restrictions in Reader are there because its capabilities are artificially crippled by Adobe. While at one point alternatives were hard to find, there's nothing magical about enabling in Acrobat Pro - unless, of course, you are using an artificially crippled reader. – cfr Dec 07 '13 at 03:36