How to Add a Digital Signature to a PDF in Python (Free & Fast)

Casie LiuCasie Liu
6 min read

Want to digitally sign a PDF without relying on expensive tools or manual work? In this guide, you'll learn how to add a digital signature to a PDF using Python—quickly, easily, and for free. Whether you're processing contracts, automating reports, or building a document system, this method requires no Adobe Acrobat. Let’s dive in and sign PDFs the smart way.

What Is a Digital Signature in PDF?

A digital signature in a PDF is a type of electronic signature that uses encryption technology to ensure the authenticity and integrity of the document. Unlike a simple image-based signature, a digital signature is legally binding and can verify both the signer’s identity and whether the document has been altered after signing.

Adding a digital signature to a PDF helps protect against tampering, builds trust with recipients, and ensures compliance with legal and regulatory standards—especially in contracts, invoices, or official records.

Add a Visible Digital Signature to PDF Using Python

When working with sensitive PDF documents—such as business contracts or confidential files—adding a digital signature is a common way to enhance both the legal validity and credibility of the content. If you're looking for a quick and efficient way to sign one or multiple PDF files, the free edition of Spire.PDF for Python is a great option. It allows you to insert digital signatures without relying on Adobe Acrobat—and even without opening the PDF manually.

Steps to add a visible digital signature to a PDF:

  • Create an object of the PdfDcument and read a source PDF from files.

  • Create a PdfOrdinarySignatureMaker object and pass the PdfDocument object, certificate (.pfx) file path and certificate password to the class instructor as parameters.

  • Specify signature details using the properties of the PdfOrdinarySignatureMaker class.

  • Create a PdfSignatureAppearance instance for the signature, and then customize the signature.

  • Get a certain page of the PDF through the PdfDocument.Pages[] property.

  • Add the signature to the page with the PdfOrdinarySignatureMaker.MakeSignature() method.

  • Save the digitally signed PDF as a new one.

from spire.pdf.common import *
from spire.pdf import *

# Create a PdfDocument instance
doc = PdfDocument()
# Load a PDF file
doc.LoadFromFile("/Booklet.pdf")

# Create a signature maker
signatureMaker = PdfOrdinarySignatureMaker(doc, "/Alice.pfx", "e-iceblue")

# Configure the signature properties like the signer's name, contact information, location and signature reason
signature = signatureMaker.Signature
signature.Name = "Alice"
signature.ContactInfo = "12345678"
signature.Location = "SaltLake City"
signature.Reason = "I am the author."

# Create a custom signature appearance
appearance = PdfSignatureAppearance(signature)
# Set label for the signer's name
appearance.NameLabel = "Signer: "
# Set label for the contact information
appearance.ContactInfoLabel = "Phone: "
# Set label for the location
appearance.LocationLabel = "Location: "
# Set label for the signature reason
appearance.ReasonLabel = "Reason: "
# Set signature image
appearance.SignatureImage = PdfImage.FromFile("/signature.png")
# Set the graphic render/display mode for the signature
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail
# Set the layout for the signature image
appearance.SignImageLayout = SignImageLayout.none

# Get the first page
page = doc.Pages[0]

# Add the signature to a specified location of the page
signatureMaker.MakeSignature("Signature by Alice", page, 90.0, 600.0, 260.0, 100.0, appearance)

# Save the signed document
doc.SaveToFile("/DSigned.pdf")
doc.Close()

Add a Digital Signature in PDF Using Python

Add an Invisible Digital Signature (Certified PDF)

In the previous section, we demonstrated how to add a visible signature to a PDF. Now, let’s take it a step further and learn how to add an invisible signature. Although it doesn't appear on the page, an invisible signature still plays an important role in verifying the document’s source and ensuring its security. Surprisingly, the process is even simpler than adding a visible signature—requiring fewer steps. Let’s take a look.

Steps to add an invisible digital signature in a PDF:

  • Create an instance of the PdfDocument class and load a PDF file.

  • Create a PdfOrdinarySignatureMaker object and pass the PdfDocument object, certificate (.pfx) file path and certificate password to the class instructor as parameters.

  • Add a signature in the PDF using the PdfOrdinarySignatureMaker.MakeSignature() method.

  • Save the updated PDF.

from spire.pdf.common import *
from spire.pdf import *

# Create a PdfDocument instance
doc = PdfDocument()
# Load a PDF document
doc.LoadFromFile("/Booklet.pdf")

# Create a signature maker
signatureMaker = PdfOrdinarySignatureMaker(doc, "/gary.pfx", "e-iceblue")

# Add an invisible signature to the document
signatureMaker.MakeSignature("Signature by Gary")

# Save the signed document
doc.SaveToFile("/InvisibleSignature.pdf")
doc.Close()

Online Tools vs SDKs: Which One Should You Choose?

When searching for ways to add digital signatures to PDFs, you’ve probably seen various online PDF signing tools like Smallpdf or iLovePDF. To help you choose the best solution, the table below compares this type of online tool with Spire.PDF for Python.

FeatureOnline PDF Signing ToolsSpire.PDF for Python
CostUsually free with limitations✅ Free version available (no watermark)
SecurityUploading files to third-party servers✅ Local processing, more secure
Internet Required✅ Yes❌ No – works entirely offline
Customization❌ Limited (predefined signature fields)✅ Full control over signature placement, style, and logic
Automation❌ Manual upload each time✅ Can batch sign multiple PDFs via code
Integration with Projects❌ Not suitable for backend or scripts✅ Easily integrated into Python projects
Signature Types SupportedMostly visible signatures only✅ Supports both visible and invisible digital signatures
File Size / Upload Limits❌ Yes – often limited✅ No file size limits (handled locally)
Signing CertificatesSome support limited certificate options✅ Full support for .pfx certificate files

If you only need to sign a few documents occasionally, online tools are quick and easy to use. However, for automated, large-scale, or offline processing, Spire.PDF for Python is a more flexible and secure choice.

The Conclusion

In this guide, we explored both visible and invisible signature options using Python and compared them with popular online tools. Whether you're looking for a quick solution or a scalable, automated approach, choosing the right tool depends on your specific needs!

FAQs about Adding Digital Signatures to PDFs

1. How do I insert or create a digital signature in a PDF?

You can insert a digital signature into a PDF using tools like Spire.PDF for Python, Adobe Acrobat, or various online services. The process usually involves selecting a digital certificate and applying it to the document to ensure authenticity and integrity.

2. How do I add an electronic signature to a PDF?

An electronic signature can be added by inserting an image of your handwritten signature or using specialized software that supports digital signing. Many PDF editors and online tools offer simple ways to place your signature on the document.

0
Subscribe to my newsletter

Read articles from Casie Liu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Casie Liu
Casie Liu