[Tex/LaTex] Locking Fields in Digital Signature

formspdf

I am using eforms to create pdf where digital signature can be applied. Each document may have more than one digital signature field, ie so the document can be passed from person to person.

There is an added complexity here in the sense that depending on the parameters parsed to the custom command, \mySigField{...}, the username and title fields are either editable or not. In other words, the 4th and 5th argument represents the name and position respectively. If those input arguments are empty, an editable field is created, if they contain something, that something is printed and no editable field is created.

My Question is, in the event that there is at least one editable related field, how can I lock that field or fields once the particular user has signed.

The following sample output:

Output

is produced with the following code:

\documentclass{article}

\usepackage{varwidth}
\usepackage{hyperref}
\usepackage[pdftex]{eforms}
\usepackage{xcolor}
\usepackage{xifthen}

\def\colFeat{blue!50!black} %Feature Color 1 for Main Color Theme.

\makeatletter
    \def\eq@SigField{\centerWidget\eq@rectH
        \if\autoCenter n\eqcenterWidget=0pt\fi
        \leavevmode\hbox{\pdfstartlink user{\common@SigFieldCode}%
        \lower\eqcenterWidget\Bbox{\eq@rectW}{\eq@rectH}\pdfendlink}%
        \endgroup
    }
\makeatother

\newcommand{\mySigField}[5]{
    \begin{varwidth}{#2}
        \textcolor{\colFeat}{
            \fcolorbox{black!5!white}{black!5!white}{\sigField{#1}{#2}{#3}}\\[1mm]
            \rule{#2+3mm}{2pt}\\[2mm]
            \begin{tabular}{rl}
                \raggedleft Name: & \ifthenelse{\equal{#4}{}}{\TextField[name=name#1,width=6cm]{}}{#4}\\\\[-3mm]
                \raggedleft Position: & \ifthenelse{\equal{#5}{}}{\TextField[name=pos#1,width=6cm]{}} {#5}
            \end{tabular}
        }
    \end{varwidth}
}

\begin{document}
\def\WS{8cm}
\def\HS{2.5cm}
\section{Example of No Related Fields}
\mySigField{PERSONA}{\WS}{\HS}{John Smith}{Garbo}
\section{Example of One Related Field}
\mySigField{PERSONB}{\WS}{\HS}{Jane Doe}{}
\section{Example of Two Related Fields}
\mySigField{PERSONC}{\WS}{\HS}{}{}
\end{document}

Best Answer

According to the PDF specification (p. 446f), it is possible to specify the form fields that shouldn't be changed any more once a signature field has been signed in a so-called sigature field lock dictionary. With the eforms package, the code for your signature field in \mySigField to do this would be:

\sigField[\Lock{/Action/Include/Fields [(name#1)(pos#1)]}]{#1}{#2}{#3}

The names of the form fields that should be locked are given in round brackets. Other possible specifications are \Lock{/Action/All} to lock all form fields, and \Lock{/Action/Exclude/Fields [(field1)(field2)...]} to lock all fields apart from the specified ones.

In your example, the code above would specify non-existing form fields if one or both of the arguments for name and position are supplied, so it is possibly cleaner to use a series of conditions:

\ifthenelse{\equal{#4}{}}%
  {\ifthenelse{\equal{#5}{}}%
    {\sigField[\Lock{/Action/Include/Fields [(name#1)(pos#1)]}]{#1}{#2}{#3}}%
    {\sigField[\Lock{/Action/Include/Fields [(name#1)]}]{#1}{#2}{#3}}%
  }%
  {\ifthenelse{\equal{#5}{}}%
    {\sigField[\Lock{/Action/Include/Fields [(pos#1)]}]{#1}{#2}{#3}}%
    {\sigField{#1}{#2}{#3}}%
  }%

Unfortunately, I'm not able to test whether this works as expected, as I don't own Adobe Acrobat to actually fill one of the fields with a signature.