I would like to create a PDF document in TeX with a form. Some of the fields in the form will be calculated based on the values of other fields.
Here is a MWE, thanks to Victor Ivrii on the pdftex mailing list back in 2005:
\documentclass{article}
\usepackage[pdftex]{hyperref}
\begin{document}
\begin{Form}
\TextField[maxlen=40,keystroke={AFNumber_Keystroke(2, 0, 1, 2,
true);},align=2,height=10pt,width=45pt,name=alpha]{Alpha}
\bigskip
\TextField[maxlen=40,keystroke={AFNumber_Keystroke(2, 0, 1, 2,
true);},align=2,height=10pt,width=45pt,name=beta]{Beta}
\bigskip
\TextField[maxlen=40,keystroke={AFNumber_Keystroke(2, 0, 1, 2, true);},
calculate={AFSimple_Calculate("SUM" , new Array ( "alpha" , "beta" )
;)}, align=2,height=10pt,width=45pt,name=gamma,readonly=true]{Gamma}
\end{Form}
\end{document}
The resulting PDF has three fields, and the third is supposed to automatically update to be the sum of the first two. If I compile the document and open in Acrobat, I can edit the first two fields (alpha
and beta
) but the third (gamma
) does not update. No JavaScript errors are thrown.
If I examine the properties of the field gamma
in Acrobat, I can see that its calculate
property is set to be the sum of the to fields alpha
and beta
.
If I select "Pick...", I'm shown a dialog with the three fields, and alpha
and beta
are selected. If I deselect and reselect those fields and accept, the form now works as desired (Acrobat-altered document at scribd). The diff
command tells me the PDF file has changed but not how.
I have found some discussion about this on the pdftex mailing list, in the above referenced thread and again here. Ralf Uterman apparently posted a patch as a result of the second thread, but as far as I can tell the issue persists. I have tried the eforms
package from the AcroTeX bundle as well, but the author writes in the manual that "Calculate works correctly when drivers dvips
, dvipsone
, or dvipdfm
are used." (pdftex
is not listed).
Yet I cannot get this to work under any driver. If I use the dvips
driver to compile to DVI, then dvips
to convert to PostScript, then convert to PDF using either Acrobat Distiller, I get the same non-functioning form as with pdftex
. If I use the dvipdf
driver, then dvipdf
to convert to PDF, all the form elements are unrecognized and ignored.
This document is going to be stamped over a scanned PDF so I really need no other output except the form and some basic marks. So I'm flexible as to engine, driver, etc., but so far I'm not getting anything to work without manual intervention via Acrobat. I'm aware of the related question “ hyperref: how to format text in a forms text-field ” but I can't get the calculations to work in the accepted answer there, either.
scribd.com
requires registration to allow download! But it does not matter since you have a good answer below.