# Adding a signature field to PDF and signing it

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{eforms}
\usepackage{aeb_pro}
%\begin{docassembly}
%\signInfo{cSigFieldName:"mySig",ohandler:security.PPKLiteHandler,cert:"D_P_Story.pfx",password:"dps017",oInfo:{location:"Niceville, FL",reason:"I am approving this document",contactInfo:"dpstory@acrotex.net",appearance:"My Signature"}};
%\signatureSign
%\end{docassembly}
\begin{document}
\sigField[\BC{0 0 0}]{mySig}{2in}{4\baselineskip}
\end{document}


will create a PDF file containing a signature field. When uncommenting the four lines of commented code, pdflatex compilation will throw an error:

[...]
) (docassembly.djs
(C:\Users\xxx\AppData\Local\Programs\MiKTeX\tex/latex/acrotex\dljscc.def)
! Undefined control sequence.
\expVerb ->\signInfo
{cSigFieldName:"mySig",ohandler:security.PPKLiteHandler...
l.18 ...@acrotex.net",appearance:"My Signature"}};

?


I've taken this code from the eforms manual. It is required to specify the filename of the .pfx to be used for signing, where app.getPath( {cCategory:"user"})/Security is the directory where Acrobat's .pfx files are being held. I'm pretty sure that this is C:\Users\xxx\AppData\Roaming\Adobe\Acrobat\DC\Security. However, I think this might have changed for Acrobat as it is suggested that signatures are now stored in files reader_fss_signature_initials and reader_fss_signature_initialsi.

a) I'm getting the feeling that the Undefined control sequence error is rather related to some incompatibility (up-to-date MiKTeX running on Windows 10) than to a missing .pfx file (of course, I do not have the package author's D_P_Story.pfx at hand).

b) Is there any procedure to have the signing of LaTeX-generated PDFs automated during compilation time or first opening of the PDF? Obviously, .pfx files aren't file-system accessible anymore (using Acrobat Pro DC 2021.x here).

• I suspect that the manual if faulty here. docassembly is defined as a execJS environment, and these should contain javascript and not latex code. Write the author a mail and ask. (But I'm not sure if it is a good idea to use code which requires that you write down your password verbatim in a tex file.) Apr 16, 2021 at 6:58

First, I made sure that aeb_pro is properly installed, see chapter 2.7 of the manual and install_jsfiles.pdf in C:\Program Files\MiKTeX\doc\latex\aeb-pro. From cmd.exe, I created all folders on the way to %AppData%\Adobe\Acrobat\Privileged\DC\JavaScripts and copied aeb.js and aeb_pro.js to this location. I obtained the .js files from here.

I got into touch with the package author Dr. Story who was very helpful. First, he recommended reading two (1, 2) of his articles. The docassembly environment may contain LaTeX code which must be expanded to JS. I think there's a small mistake in the eforms manual as the command is \sigInfo{} instead of \signInfo{}. Thus, the code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{eforms}
\usepackage{aeb_pro}
\begin{docassembly}
\sigInfo{
cSigFieldName:"mySig",
ohandler:security.PPKLiteHandler,
cert:"xxx.pfx", % insert name of .pfx located in %AppData%\Adobe\Acrobat\DC\Security
oInfo:{
location:"Niceville, FL",
reason:"I am approving this document",
contactInfo:"dpstory@acrotex.net",
% appearance:"My Signature" % only uncomment and set this if you actually have an appearance defined
}
};
\signatureSign
\end{docassembly}
\begin{document}
\sigField[\BC{0 0 0}]{mySig}{2in}{4\baselineskip}
\end{document}


will compile successfully and (next to a .pdf file) also produce docassembly.djs and docassembly.fdf. When opening the PDF with Acrobat, the JavaScript code will be imported from docassembly.fdf. The signature field should be signed automatically. At present, only .pfx files located in %AppData%\Adobe\Acrobat\DC\Security are supported. According to my knowledge, certificates located in the Windows Certificate Store are not supported at present.

If you are not on Windows then aeb_pro isn't going to cut it for you (it requires Acrobat Reader to be installed and incorporates it into the workflow). Now that poppler supports signatures, you can use pdfsig to sign your PDF after you have incorporated a signature field. For example, to sign the first signature field use:

pdfsig -sign 1 -nick 'NAME OF SIGNATURE' in.pdf out.pdf


where NAME OF SIGNATURE is the 'Friendly Name' of your PKCS#12 certificate in the NSS database. You can use pdfsig -list-nicks to list the currently installed signatures and their nicknames. If you don't have any certificates installed then there's a lot of tutorials on how to generate (Windows, Linux) the certificates and import them into Firefox. Note that pdfsig just applies the signature, if you want to place an image or text where the "click to sign" field was then you will need to do that separately.