This is more a collection of notes than a real tutorial, but I’ve recently learned how to make fillable PDFs with LaTeX and, since making fillable PDFs often requires an expensive license, thought some of you might find it useful.
(This is also a rough translation of my Italian blogpost on the same topic, without the swearing)
Just a word of advice before going on: LaTeX is hard and can be pretty painful to master. If you are already familiar with it, go on, otherwise, this is not a beginner’s guide (and I cannot, in good conscience, suggest to somebody to learn LaTeX).
The package
This is pretty straightforward: all the functionalities are provided by the ubiquitous hyperref
package, so you just need to use that. In fact, you’d better keep the documentation at hand, while not exactly exhaustive on the topic it’s still usefull.
Fields
There are three fields (I’ve only used two, so far):
-
TextField
: “free” text -
ChoiceMenu
: drop-down menu or radio buttons -
CheckBox
: a simple on/off checkbox
They have to be included in a Form
environment, of which you can only have one per document (my dirty hack is to wrap the whole document in the form). An MWE is something like this:
\documentclass[12pt,a4paper,openany]{memoir}
\usepackage[a4paper,margin=0.5in]{geometry}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\TextField{\textbf{Nome}}
\ChoiceMenu[default=d4]{\textbf{Wizard}}{d4,d6,d8,d10,d12}
\CheckBox{Yes}
\end{Form}
\end{document}
TextField
It just draws a fillable textbox, which is, by default, as high as the line and long 4 inches. You can adjust the size using the width
and height
optional parameters, such as:
\TextField[height=1.25cm, width=8cm]{1}
The argument is written as text (you can even format it with other LaTeX commands) on the left of the box (I have no idea about how to change the positioning, though, it’s probably hidden somewhere in the package doc).
CheckBox
Again, you can set height
and width
, and even have it checked by default with checked
:
\CheckBox[checked]{Yes}
Technically you should be able to change the checkmark to other symbols (such as a WoD-style dot), but be aware that some PDF viewers will not abide (Preview on Mac is one of those). If you wanna try anyway the syntax is this \CheckBox[checkboxsymbol=\ding{108}]{Check }
and the numeric values can be found in the pifont
package documentation.
ChoiceMenu
This is a dropdown menu, but, as for the checkbox, how it is displayed is really up to the user’s software (and Preview is not nice). The syntax is pretty straightforward:
\ChoiceMenu[default=d4]{\textbf{Mago}}{d4,d6,d8,d10,d12}
While default
is optional, I’ve found out that some PDF viewers make it really hard to find an empty dropdown menu, so putting even a .
as a default value is going to make it easier on the users. The first argument is label to be displayed, the second is a comma-separated list of possible values.
For some weird reason, Preview also injects a bunch of actions such as “Copy” or “Convert to LaTeX” in the options…
Javascript
This is not something I’ve experimented with (in fact, I’m afraid to do it), but in theory you should be able to use JavaScript to validate or calculate field values, and even react on user events such as onclick
. You can find (little) more info on this in hyperref
docs.