Add Digital Signature to PDF using Python

Digital signature generation and verification using server-side Aspose.PDF for Python for .NET APIs. Native and high performance library

How to add Digitally Sign to PDF File Using Python for .NET Tool

In order to add digital signature in PDF file, we’ll use Aspose.PDF for Python via .NET, a powerful and easy-to-use API. Open PyPI, search for aspose-pdf, and install it. Alternatively, run the command:

Console

pip install aspose-pdf

Add Digitally Sign to PDF using Python


You need Aspose.PDF for Python via .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Load all the PDF files with full path.
  3. Set the style of text like font, font size, color etc.
  4. Save PDF file, You will get the document with signature inserted.
  5. To verify the validity of the signature use PdfFileSignature.VerifySigned() method.

Add Electronic Signature to a PDF File using - Python

This sample code shows how to Signature PDF Pages - Python

Input file:

File not added

Certificate file:

File not added

Output format:

Output file:

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

signature = apdf.facades.PdfFileSignature(document)
# Use PKCS7/PKCS7Detached objects
pkcs = apdf.forms.PKCS7("my_certificate.pfx", "Pa$$w0rd12345")

signature.sign(1, True, apdf.Rectangle(300, 100, 400, 200, True), pkcs)
# Save output PDF file
signature.save(path_outfile)