This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /blog/how-to-digitally-sign-pdf-in-python.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. How to digitally sign a PDF in Python (2026)

Table of contents

    How to digitally sign a PDF in Python (2026)
    One Python library for the full PDF lifecycle

    Extraction, merging, OCR, forms, and signatures in a single SDK — install with pip.

    TL;DR

    Use Nutrient Python SDK to add certificate-based digital signatures to PDFs. Signing requires a PKCS#12 (.pfx or .p12) digital ID containing the signer’s certificate and private key. The examples cover invisible and visible signatures, trusted timestamps, and document certification.

    When a Python application produces a report or approval document, recipients may need to check who signed it and whether it changed afterward. Nutrient Python SDK adds certificate-based signatures, with options for a visible appearance, a timestamp, and certification permissions.

    Choose an example based on what recipients need to check:

    Recipient needsExample
    Check the signature without adding a visible mark to the pageInvisible signature
    See an approval area and validate the signatureVisible signature
    Check the signing time independently of the signing machine’s clockTimestamped signature
    Fill in forms or sign without breaking the document’s certificationCertification that permits form filling

    Digital signatures, signature images, and signature fields

    • A certificate-based digital signature links a signed document revision to a certificate. Validation checks the document’s integrity, but trusting the signer also requires checking the certificate.
    • An image or ink signature places a drawn or scanned signature on the page as visual content, with no cryptographic protection.
    • A signature form field reserves a place in the document for someone to sign later.

    A visible digital signature displays text or an image in a signature field alongside the cryptographic signature. For more on how signing works, see PDF digital signatures.

    What signing a PDF in Python requires

    Alongside the input PDF, signing requires:

    • A digital ID — A PKCS#12 file (.pfx or .p12) containing a certificate and its private key. Use a certificate that recipients can validate under their trust policy. The public sample certificate is for testing only.
    • The SDK — Nutrient Python SDK handles certificate loading, hashing, and writing the signature into the PDF structure. The signing API is the Signature class, configured with DigitalSignatureOptions.

    Setup

    Create a working folder and open a terminal there. The commands below use macOS or Linux. Create a Python virtual environment and install the SDK:

    Terminal window
    python3 -m venv .venv
    source .venv/bin/activate
    python3 -m pip install nutrient-sdk

    On Windows, activate the environment with .venv\Scripts\Activate.ps1 in PowerShell. Check the installation guide for supported Python versions and platforms.

    Download the ZIP from the invisible signature sample and copy input.pdf and certificate.pfx into the working folder. The examples use that public test certificate and its published password. Keep production certificates, private keys, and passwords out of source control.

    Each script registers the SDK before opening a document. The examples read a license key from NUTRIENT_LICENSE_KEY and fall back to trial mode when it isn’t set. This is an SDK license, not a cloud API key. See the license activation guide for details.

    Sign a PDF with an invisible digital signature

    An invisible signature adds the cryptographic signature and its metadata without adding a visible signature appearance. Save this complete example as sign_pdf.py in the working folder:

    import os
    from nutrient_sdk import DigitalSignatureOptions, Document, License
    from nutrient_sdk import NutrientException, Signature
    def main():
    try:
    License.register_key(os.environ.get("NUTRIENT_LICENSE_KEY", ""))
    with Signature() as signer, Document.open("input.pdf") as document:
    options = DigitalSignatureOptions()
    options.certificate_path = "certificate.pfx"
    options.certificate_password = "Nutrient answers all your document needs"
    options.signer_name = "John Doe"
    options.reason = "Document Approval"
    options.location = "New York"
    options.contact_info = "john@example.com"
    signer.sign(document, "output_signed_invisible.pdf", options)
    print("Saved output_signed_invisible.pdf")
    except (NutrientException, OSError) as error:
    raise SystemExit(f"Signing failed: {error}") from error
    if __name__ == "__main__":
    main()

    Run it from the folder containing the PDF and certificate:

    Terminal window
    python3 sign_pdf.py

    The output PDF carries the signature. The signer name, reason, and location are descriptive fields that don’t change the identity in the certificate, so check the certificate when you verify the result.

    Sign a PDF with a visible signature

    A visible signature renders an appearance inside a signature field. Save both code blocks in this section, in order, as sign_visible.py. First, add the field to the page with PdfEditor:

    import os
    from contextlib import closing
    from nutrient_sdk import Document, License, NutrientException, PdfEditor
    from nutrient_sdk import DigitalSignatureOptions, Signature, SignatureAppearance
    def add_signature_field():
    with Document.open("input.pdf") as document:
    with closing(PdfEditor.edit(document)) as editor:
    page = editor.page_collection.first
    editor.form_field_collection.add_signature_field(
    name="ApprovalSignature",
    page=page,
    x=100.0,
    y=700.0,
    width=200.0,
    height=50.0
    )
    editor.save_as("output_document_with_field.pdf")

    Then sign that field with sign_field() and a SignatureAppearance. Setting use_auto_generated_text builds the appearance text from the signer metadata:

    def main():
    try:
    License.register_key(os.environ.get("NUTRIENT_LICENSE_KEY", ""))
    add_signature_field()
    with Signature() as signer, Document.open("output_document_with_field.pdf") as document:
    options = DigitalSignatureOptions()
    options.certificate_path = "certificate.pfx"
    options.certificate_password = "Nutrient answers all your document needs"
    options.signer_name = "John Doe"
    options.reason = "Final Approval"
    options.location = "New York"
    appearance = SignatureAppearance()
    appearance.use_auto_generated_text = True
    appearance.show_validation_mark = True
    signer.sign_field(
    document,
    "output_signed_visible.pdf",
    "ApprovalSignature",
    options,
    appearance
    )
    except (NutrientException, OSError) as error:
    raise SystemExit(f"Signing failed: {error}") from error
    if __name__ == "__main__":
    main()

    Run python3 sign_visible.py from the working folder. To customize the appearance, set an image_path for a handwritten signature or logo, or use the text and font settings on SignatureAppearance. See the visible signature examples for these options.

    Verify the signature

    Open the signed PDF in a reader that supports digital-signature validation and check its signature panel. Inspect the certificate identity, integrity result, trust status, and any changes after signing. The visible name or validation mark alone isn’t proof that a signature is valid or trusted.

    A test certificate may show as untrusted even when the document’s signature is intact. Certificate trust, revocation checks, and allowed changes are separate parts of validation. Don’t rely on a browser preview that only displays the page.

    Add a timestamp with PAdES

    A signature’s recorded time normally comes from the signing machine’s clock. A timestamp from a trusted time stamp authority (TSA) provides independent evidence of when the signature existed. Long-term validation also depends on certificate and revocation evidence.

    PDF Advanced Electronic Signatures (PAdES) defines signature profiles. Save the script below as sign_timestamp.py to request a B-T signature with a timestamp:

    import os
    from nutrient_sdk import Document, License, NutrientException, Signature
    from nutrient_sdk import DigitalSignatureOptions, TimestampConfiguration
    from nutrient_sdk import SignatureLevel
    def main():
    try:
    License.register_key(os.environ.get("NUTRIENT_LICENSE_KEY", ""))
    with Signature() as signer, Document.open("input.pdf") as document:
    options = DigitalSignatureOptions()
    options.certificate_path = "certificate.pfx"
    options.certificate_password = "Nutrient answers all your document needs"
    options.signer_name = "Legal Department"
    options.reason = "Contract Execution"
    options.level = SignatureLevel.PADES_BASELINE_T
    timestamp = TimestampConfiguration()
    timestamp.server_url = "http://timestamp.digicert.com"
    options.timestamp = timestamp
    signer.sign(document, "output_pades_t.pdf", options)
    except (NutrientException, OSError) as error:
    raise SystemExit(f"Signing failed: {error}") from error
    if __name__ == "__main__":
    main()

    Run python3 sign_timestamp.py. The request needs access to the TSA endpoint; handle network failures before treating the output as complete. Check the timestamp in the reader’s signature properties.

    PAdES is the default signature format. B-T adds a trusted timestamp, B-LT adds certificates and revocation information, and B-LTA adds a document timestamp for archival. See the PAdES guide for the requirements of each level.

    Certify a document

    A certifying signature declares which changes remain allowed after signing. It must be the first signature on the document, and a document can have only one. Save the script below as certify_pdf.py and use the original unsigned input.pdf:

    import os
    from nutrient_sdk import Document, License, NutrientException, Signature
    from nutrient_sdk import DigitalSignatureOptions
    from nutrient_sdk import SignatureCertificationLevel
    def main():
    try:
    License.register_key(os.environ.get("NUTRIENT_LICENSE_KEY", ""))
    with Signature() as signer, Document.open("input.pdf") as document:
    options = DigitalSignatureOptions()
    options.certificate_path = "certificate.pfx"
    options.certificate_password = "Nutrient answers all your document needs"
    options.signer_name = "Document Author"
    options.reason = "Certifying document integrity"
    options.certification = SignatureCertificationLevel.FORM_FILLING
    signer.sign(document, "output_certified.pdf", options)
    except (NutrientException, OSError) as error:
    raise SystemExit(f"Signing failed: {error}") from error
    if __name__ == "__main__":
    main()

    Run python3 certify_pdf.py. Choose a certification level based on the changes recipients need to make. FORM_FILLING permits form filling and signing; FORM_FILLING_AND_ANNOTATIONS also permits annotations. With NO_CHANGES, changes invalidate the certification.

    How the examples were tested

    All four scripts ran with Nutrient Python SDK 1.0.13 in trial mode using the public sample PDF and test certificate. OpenSSL verified each output’s cryptographic signature and rejected copies with altered signed bytes. The outputs also contained the visible signature appearance, timestamp token, and certification permissions that each example requested.

    These checks didn’t establish certificate or TSA trust, or full PAdES conformance. When you evaluate the SDK with a production certificate, check the output in the reader your recipients use.

    Troubleshoot signing errors

    If signing fails, discard any partial output before retrying. A partial file can exist even when signing failed, so check the script’s result and validate the signature.

    • Missing input or certificate — Run the scripts from the folder containing input.pdf and certificate.pfx, or use absolute paths.
    • Certificate loading fails — Check the PKCS#12 password and confirm the file contains a private key as well as a certificate.
    • SDK initialization fails — Register the SDK license before opening documents. A cloud API key doesn’t activate the SDK.
    • Timestamp request fails — Check connectivity to the TSA and its service requirements. Don’t assume an untimestamped output meets the requested B-T profile.

    Add PDF signing to a Python application

    Nutrient Python SDK combines PDF editing, form handling, and signing in one library. For an application that prepares documents before issuing them, those steps can use the same SDK. Complete the document edits before signing. Then choose the signature appearance, timestamp, and certification permissions the workflow needs.

    Start with the Python signing examples and a representative PDF. Validate the resulting signature in the recipient’s reader before adding signing to the application’s document workflow. The application still needs to manage private keys, certificate trust, and any recipient or approval process.

    Sign PDFs in Python with Nutrient

    FAQ

    Install Nutrient Python SDK and register the SDK license. Open the PDF with Document.open(), set the certificate path and password on DigitalSignatureOptions, and call sign() on a Signature instance. The output PDF carries a certificate-based digital signature.

    Nutrient Python SDK signs with a PKCS#12 digital ID (.pfx or .p12), which contains the certificate and its private key. Use a test certificate for development and a certificate that recipients can validate for production.

    Both are cryptographic signatures. An invisible signature leaves the pages unchanged, while a visible signature also draws an appearance, such as text or an image, inside a signature field on the page.

    A reader that validates digital signatures can identify changes made after signing. A certifying signature can permit specific changes, such as form filling, without invalidating the certification.

    Yes. PAdES is the default signature format in Nutrient Python SDK, and the level property selects baseline levels such as B-T, which adds a trusted timestamp.

    Hulya Masharipov

    Hulya Masharipov

    Technical Writer

    Hulya is a frontend web developer and technical writer who enjoys creating responsive, scalable, and maintainable web experiences. She’s passionate about open source, web accessibility, cybersecurity privacy, and blockchain.

    Explore related topics

    Try for free Work with PDFs in Python