Forum Discussion
How to sign a PDF on laptop—do I need an electronic or digital signature?
pyHanko is a free tool for certificate-based PDF signing. If you’re comfortable running a Python script, you can sign locally without uploading your document.
You’ll need a .p12 or .pfx file containing your signing certificate and private key. Install the library first:
python -m pip install pyHanko
Put input.pdf and your certificate, here named certificate.pfx, in the same folder as this script. Save it as sign_pdf.py:
from getpass import getpass
from pyhanko.sign import signers
from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter
signer = signers.SimpleSigner.load_pkcs12(
"certificate.pfx",
passphrase=getpass("Certificate password: ").encode("utf-8"),
)
if signer is None:
raise RuntimeError("Unable to load the certificate and private key.")
with open("input.pdf", "rb") as source:
with open("signed.pdf", "wb") as destination:
signers.sign_pdf(
IncrementalPdfFileWriter(source),
signature_meta=signers.PdfSignatureMetadata(
field_name="Signature1"
),
signer=signer,
output=destination,
)
print("Created signed.pdf")
Run it from that folder:
python sign_pdf.py
This adds a digital signature without a visible handwritten image. Open signed.pdf in a reader with signature validation to check it.
The signing operation works offline. However, a self-signed certificate may show as untrusted on someone else’s computer. If the recipient requires a trusted certificate, confirm what they accept before obtaining one.