I’m trying to be better about digitally signing .pdf documents that I author as a professional engineer. And without needing to pay Adobe to use Acrobat. Enter pyHanko, which does not have a graphical user interface; however, with a little fussing it works well.
First, open Terminal.app and execute the following command to create a certificate and private key:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650
When prompted, I entered:
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:Minnesota
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Barr Engineering Co.
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:Bradford Schwie
Email Address []:bschwie@barr.com
Next combine the above generated cert.pem and key.pem into certif.p12 with this command:
openssl pkcs12 -export -out certif.p12 -in cert.pem -inkey key.pem
Verify the certificate.p12 contains a certificate and key with this command:
openssl pkcs12 -info -in certif.p12
Finally, create a .pdf with command:
pyhanko sign addsig --field Sig1 pkcs12 input.pdf output_signed.pdf certif.p12
pyhanko sign addsig --field 1/70,400,390,350/Sig1 --style-name default pkcs12 input.pdf output_signed.pdf certif.p12
I could probably do more fussing with the signature appearance, but it took a fair amount of effort and this was before Liam bailed me out – thank you! Hopefully others find this as helpful as I do.
** Update 11-26-2025 **
Today I was signing a document that another user had already digitally signed. No sweat, pyHanko seems to handle this situation with the following example that I used:
pyhanko sign addsig --field 1/90,215,360,185/Sig1 --style-name default --no-strict-syntax pkcs12 input.pdf output_signed.pdf certif.p12
** Update 12-4-2025 **
Today I signed a couple letter documents. The following pyHanko command worked for me once I navigated to the Archive folder on the Desktop, where I had the other files discussed above.
pyhanko sign addsig --field 1/70,275,370,225/Sig1 --style-name default --no-strict-syntax pkcs12 input.pdf output_signed.pdf certif.p12
** Update 12-30-2025 **
To stamp the fourth page of a .pdf, replace “field 1” (above), with “field 4” as shown below:
pyhanko sign addsig --field 4/140,150,410,120/Sig1 --style-name default --no-strict-syntax pkcs12 input.pdf output_signed.pdf certif.p12
** Update 2-24-2026 **
For moving the signature around, I have found that keep the height of the signature box constant allows you to widen the box to create separation between the signature graphic and the date. This gets me separation on the first page of a wide form:
pyhanko sign addsig –field 1/90,108,520,78/Sig1 –style-name default –no-strict-syntax pkcs12 input.pdf signed.pdf certif.p12