pdfsig ignores `-sign` option
It seems that pdfsig
does not fill in an existing signature form field when signing the PDF. It merely appends an invisible signature while the signature field remains untouched. Neither addressing the signature field by index (-sign 0
) nor by field name (-sign "my signature"
) works.
For testing, I attach a sample PDF with a text field and with a single signature field (internal name "my signature
") at the bottom of the page:
This is the command line I use:
pdfsig -nssdir ~/.pki/nssdb/ -sign "my signature" -add-signature -nick my.email@address.org -nss-pwd "my secret passphrase" sample-with-sigfield.pdf sample-with-sigfield-signed.pdf
Version is poppler-23.02.0
.
This is the LaTeX source of the sample PDF, requires two runs of pdflatex
:
% sample document with signature field
% Alexander Grahn, 2023
\DocumentMetadata{} % activates the PDF management interface
\documentclass{article}
\usepackage[a6paper,twoside]{geometry}
\usepackage{pdfbase}
\ExplSyntaxOn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand\txtField{mmm}{ % args: width, height, field-id
\frame{\pbs_pdfannot:nnnn{#1}{#2}{0pt}{
/Subtype/Widget/FT/Tx/T~(#3)/F~4/Ff~4096
}\phantom{\rule{#1}{#2}}}
\pbs_appendtofields:n{\pbs_pdflastann:}
}
\NewDocumentCommand\sigField{mmm}{ % args: width, height, field-id
\frame{\pbs_pdfannot:nnnn{#1}{#2}{0pt}{
/Subtype/Widget/FT/Sig/T~(#3)/F~4
/P~\pdf_pageobject_ref:n{\int_eval:n{1+\g_pbs_page_int}}
% once signed, all form fields should be locked (not all
% viewers acknowledge this)
/Lock~<</Type/SigFieldLock/Action/All>>
}\phantom{\rule{#1}{#2}}}
\pbs_appendtofields:n{\pbs_pdflastann:}
}
\pdfmanagement_add:nnn{Catalog/AcroForm}{SigFlags}{1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOff
\begin{document}
\section{Sample document}
Please fill in the form and sign the document electronically. At the
bottom you will find a signature field. Click on it to insert a digital
signature.\\[2ex]
Enter some text:\\[1ex]
\txtField{\linewidth}{6ex}{my text field}\\[2ex]
After signing, the text field should be locked and not be modifiable anymore,
though that seems to happen only in Acrobat Reader.
\vspace{\fill}
\noindent\parbox{0.6\linewidth}{%
\centering
\sigField{\linewidth}{6ex}{my signature}\\ % named signature field
Signature
}
\end{document}