How to Sign PDF

Learn how easily sign PDF documents with high quality using Python PDF library

How to sign PDF with Python

The Electronic digital signature is a type of electronic signature that uses cryptographic methods to add and verify data integrity and signatory identification. The electronic digital signature is created by combining electronic data with cryptographic transformation through a private key and verified using a public key.

An Electronic digital signature is essential for authenticating the signer of an electronic document, and the electronic copy of the document with an electronic digital signature is considered the original. It is an integral component of the public key infrastructure.

Sign PDF using Aspose.PDF for Python via .NET

To add a digital signature to a PDF file, Aspose.PDF for .NET API can be utilized. This API is designed to provide a feature-rich, powerful, and user-friendly document manipulation experience for Python via .NET. It can be easily installed using the NuGet package manager. Alternatively, you can use the command given below from the Package Manager Console.

pip install aspose-pdf

Sign PDF files

Sign PDF

The next code sample is written in Python and uses the Aspose.PDF for .NET library. The purpose of the code is to digitally sign a PDF document using a PKCS7 certificate.

The input PDF file is named “DigitallySign.pdf” and the output signed PDF file is named “DigitallySign_out.pdf”. The code uses the Aspose.PDF Document class to load the input PDF file and then creates a PdfFileSignature object to perform the digital signature operation.

The digital signature operation is performed using the PKCS7 standard and a certificate file named “test.pfx” stored in the “C:\Keys” directory, along with its password “Pa$$w0rd2020”. The signature is added to the first page of the input PDF document, with the signature rectangle starting at coordinates (300, 100) and ending at coordinates (400, 200). Finally, the digitally signed PDF is saved as the output file.

Use following code snippet for this:

    inFile = "DigitallySign.pdf"
    outFile = "DigitallySign_out.pdf"
    document = Document(inFile)
    signature = PdfFileSignature(document)
    # Use PKCS7/PKCS7Detached objects
    pkcs = new PKCS7("C:\\Keys\\test.pfx", "Pa$$w0rd2020")
 
    signature.Sign(1, true, Rectangle(300, 100, 400, 200),pkcs)
    # Save output PDF file
    signature.Save(outFile);

Try to sign PDF files online

The digital signature application is specifically created to provide a swift and effortless means of adding a digital signature to your PDF document. To add digital signature online for free you can use this online tool

Documentation Aspose.PDF for Python Library

See other features of Aspose.PDF for Python library on Documentation pages

Conclusion

This article provides a comprehensive guide and Python code example on how to sign PDF files using Aspose.PDF for Python via .NET. Additionally, a free web-based conversion tool is available, which enables you to easily add an electronic digital signature to PDF files without any charges. If you want more details about Aspose.PDF libraries - visit our landings pages