IRONSOFTWAREHOME

How to Digitally Sign a PDF in Java

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Digitally signing a PDF in Java with IronPDF lets you apply cryptographic signatures that verify document authenticity and detect unauthorized changes. IronPDF supports PdfSignature for attaching PFX certificate-based signatures to any PDF, setting visible signature images, controlling PDF certification levels with PdfCertificationLevel, and connecting to a Timestamp Authority server for long-term signature validity.

Quickstart: Digitally Sign a PDF in Java
  1. Install IronPDF for Java via Maven or Gradle
  2. Set your license key with License.setLicenseKey()
  3. Load the PDF with PdfDocument.fromFile()
  4. Create a PdfSignature with your PFX certificate file and password
  5. Apply the signature with signDigitalSignature()
  6. Save the signed PDF with saveAs()
  1. 1Install IronPDF with Maven Central Repository

    mvn install

  2. 2Copy and run this code snippet.

    :path=/static-assets/ironpdf-java/content-code-examples/how-to/how-to-digitally-sign-pdfs-java-tutorial/quickstart.java
    Java
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

Digital signatures give PDF documents a cryptographic identity tied to a private key and certificate. When a recipient opens a signed PDF in Adobe Acrobat or any compliant viewer, the application verifies that the certificate chain traces back to a trusted authority and that the document content has not changed since signing. This combination of authentication and integrity makes digital signatures essential for contracts, invoices, regulatory filings, and any document where tamper evidence matters.

PDF signatures fall into two categories: approval signatures and author (certification) signatures. An approval signature records one signer's approval at a point in time; multiple parties can add approval signatures in sequence without invalidating earlier ones. A certification signature, applied with certify(), locks the document according to a PdfCertificationLevel and marks the signer as the document author. Certification signatures must be the first signature on a document and control what changes, if any, subsequent signers can make.

IronPDF handles both signature types through a consistent API built around PdfSignature and PdfDocument. For initial setup, dependency configuration, and license key instructions, see the Get Started Overview.

What Do I Need Before Getting Started?

Before signing PDFs with IronPDF, confirm the following prerequisites:

  • Java 8 or higher: IronPDF requires a JDK of version 8 or above.
  • IronPDF for Java: Add the dependency to your build file. Find the latest version on Maven Central.
  • A valid license key: Set the key at application startup with License.setLicenseKey(). For setup details, visit the license keys guide.
  • A PFX or P12 certificate file: This is a password-protected archive containing your private key and public certificate in PKCS#12 format. Self-signed certificates work for development and testing; for production documents that need to be trusted by external recipients, use a certificate issued by a recognized Certificate Authority (CA) such as DigiCert, Comodo, or GlobalSign.

For full dependency setup and project configuration, refer to the Get Started Overview.

How Do I Apply a Digital Signature to a PDF?

The PdfSignature constructor takes the file path to your PFX certificate and its password. Once constructed, you can attach optional metadata through three setter methods:

  • setSigningContact(String): the name or email of the person signing
  • setSigningLocation(String): the physical or organizational location of the signer
  • setSigningReason(String): a short description of why the document is being signed

These fields appear in the signature properties panel of PDF viewers and create a useful audit record for compliance purposes. Call signDigitalSignature(PdfSignature) on the loaded PdfDocument to embed the cryptographic signature, then save the result with saveAs().

import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.signature.PdfSignature;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the IronPDF license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF to sign
        PdfDocument pdf = PdfDocument.fromFile(Path.of("contract.pdf"));

        // Construct the PdfSignature with the certificate path and password
        PdfSignature signature = new PdfSignature("certificate.pfx", "password123");

        // Set metadata that will appear in the signature properties panel
        signature.setSigningContact("Jane Doe");
        signature.setSigningLocation("Austin, TX");
        signature.setSigningReason("Contract Approval");

        // Embed the digital signature in the PDF
        pdf.signDigitalSignature(signature);

        // Save the signed document
        pdf.saveAs(Path.of("contract-signed.pdf"));
    }
}
Java

After signDigitalSignature() completes, the PDF contains a cryptographic hash of the document content signed with the private key from the PFX file. Any modification to the file after this point will invalidate the signature.

How Do I Add a Visible Signature Image to a PDF?

A visible signature image places a graphical representation directly on the PDF page at the location of the signature field. This is commonly used to display a scanned handwritten signature, a company stamp, or a logo so that the document looks signed when printed or viewed, not only when inspected with a PDF reader's signature panel.

To add a visible image, open the image file as a FileInputStream and pass it to PdfSignature.setSignatureImage(InputStream) before calling signDigitalSignature(). The image is embedded within the signature field on the page.

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.signature.PdfSignature;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the IronPDF license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF document to sign
        PdfDocument pdf = PdfDocument.fromFile(Path.of("agreement.pdf"));

        // Build the PdfSignature from a PFX certificate
        PdfSignature signature = new PdfSignature("certificate.pfx", "password123");

        // Set signing metadata
        signature.setSigningContact("Alice Johnson");
        signature.setSigningLocation("Chicago, IL");
        signature.setSigningReason("Agreement Authorization");

        // Open the signature image file and attach it to the signature
        FileInputStream imageStream = new FileInputStream("signature.png");
        signature.setSignatureImage(imageStream);

        // Apply the digital signature with the visible image to the PDF
        pdf.signDigitalSignature(signature);

        // Save the signed PDF with the visible signature image embedded
        pdf.saveAs(Path.of("agreement-signed.pdf"));
    }
}
Java

The signature image does not replace the cryptographic protection; both the graphical stamp and the underlying certificate remain part of the signed output. PNG and JPEG formats are supported for the signature image.

How Do I Certify a PDF With a Specific Permission Level?

Certifying a PDF differs from adding an approval signature. When you call pdf.certify(PdfSignature, PdfCertificationLevel), you sign the document as its author and specify which types of changes are permitted by subsequent users. A certified PDF displays a blue ribbon or similar trust indicator in Adobe Acrobat, signaling to recipients that the document comes from a verified source.

IronPDF provides three certification levels through the PdfCertificationLevel enum:

  • PdfCertificationLevel.NO_CHANGES_ALLOWED: the document is fully locked after certification; no further modifications are permitted.
  • PdfCertificationLevel.FORM_FILLING: recipients may fill in form fields but cannot add comments, annotations, or other changes.
  • PdfCertificationLevel.FORM_FILLING_AND_ANNOTATIONS: recipients may fill in form fields and add annotations, but structural edits are still prohibited.

Because a certification signature must be the first signature on a document, call certify() before applying any approval signatures from other parties.

import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.signature.PdfCertificationLevel;
import com.ironsoftware.ironpdf.signature.PdfSignature;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the IronPDF license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF that will be certified
        PdfDocument pdf = PdfDocument.fromFile(Path.of("report.pdf"));

        // Create the PdfSignature from the author's certificate
        PdfSignature signature = new PdfSignature("author-certificate.pfx", "password123");

        // Set author metadata for the certification signature
        signature.setSigningContact("Legal Department");
        signature.setSigningLocation("San Francisco, CA");
        signature.setSigningReason("Official Publication");

        // Certify the document with NO_CHANGES_ALLOWED to lock it completely
        // Use FORM_FILLING to allow form field input after certification
        // Use FORM_FILLING_AND_ANNOTATIONS to also permit annotations
        pdf.certify(signature, PdfCertificationLevel.NO_CHANGES_ALLOWED);

        // Save the certified PDF
        pdf.saveAs(Path.of("report-certified.pdf"));
    }
}
Java

Once certified with NO_CHANGES_ALLOWED, any attempt to modify the PDF will break the certification signature and PDF viewers will display a warning. Choose FORM_FILLING or FORM_FILLING_AND_ANNOTATIONS when the certified document needs to be filled out or annotated by downstream recipients without invalidating the author's certification.

How Do I Add a Timestamp to a Digital Signature?

A Timestamp Authority (TSA) server provides a cryptographically signed time token that gets embedded alongside the signature in the PDF. This timestamp proves when the signature was applied, independent of the signer's local clock. Long-term validity depends on timestamps: even after a signing certificate expires, a trusted timestamp allows validators to confirm that the signature was created while the certificate was still valid.

To enable timestamping, set two properties on the PdfSignature object before signing:

  • setTimestampHashAlgorithm(PdfHashAlgorithm): specifies the hashing algorithm to use when computing the timestamp token. PdfHashAlgorithm.SHA256 is the standard choice.
  • setTimestampUrl(String): the HTTP or HTTPS endpoint of the TSA server that will issue the timestamp token.

Several TSA servers are available at no cost for testing and low-volume production use. https://freetsa.org/tsr and http://timestamp.digicert.com are two commonly used endpoints.

import java.io.IOException;
import java.nio.file.Path;
import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.signature.PdfHashAlgorithm;
import com.ironsoftware.ironpdf.signature.PdfSignature;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the IronPDF license key
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load the PDF to sign with a timestamp
        PdfDocument pdf = PdfDocument.fromFile(Path.of("invoice.pdf"));

        // Construct the PdfSignature from the certificate file
        PdfSignature signature = new PdfSignature("certificate.pfx", "password123");

        // Set signature metadata
        signature.setSigningContact("Finance Team");
        signature.setSigningLocation("Seattle, WA");
        signature.setSigningReason("Invoice Authorization");

        // Configure the timestamp: set the hash algorithm and TSA endpoint
        signature.setTimestampHashAlgorithm(PdfHashAlgorithm.SHA256);
        signature.setTimestampUrl("https://freetsa.org/tsr");

        // Apply the digital signature; IronPDF will contact the TSA to obtain
        // and embed a timestamp token alongside the cryptographic signature
        pdf.signDigitalSignature(signature);

        // Save the timestamped, signed PDF
        pdf.saveAs(Path.of("invoice-signed-timestamped.pdf"));
    }
}
Java

When the TSA is unreachable at signing time, IronPDF will throw an exception; verify network access and the TSA endpoint URL before deploying to production. For high-volume production workflows, consider a commercial TSA subscription to ensure uptime and throughput guarantees.

What Are the Next Steps for Digitally Signing PDFs in Java?

IronPDF's PdfSignature class covers the full range of PDF signature requirements: approval signatures with certificate metadata, visible graphical stamps, PDF certification with access control levels, and TSA-backed timestamps for long-term validity. To extend your PDF workflow beyond signing, explore these related resources:

Start your free trial to add digital signatures to your Java PDF workflow. To purchase a license for production use, view licensing options.

Frequently Asked Questions

How does IronPDF help in digitally signing PDFs in Java?

IronPDF provides a simple yet powerful API to apply cryptographic signatures to PDFs, allowing verification of document authenticity and detection of unauthorized modifications. It supports features like PFX certificate-based signatures, visible signature images, PDF certification levels, and timestamping for long-term signature validity.

What is required to digitally sign a PDF using IronPDF in Java?

To start digitally signing PDFs with IronPDF in Java, you need Java 8 or higher, the IronPDF Java library installed via Maven or Gradle, a valid IronPDF license key, and a PFX or P12 certificate file for the signature.

How can I apply a visible signature image using IronPDF?

You can add a visible signature image by opening the image file as a FileInputStream and using the PdfSignature.setSignatureImage(InputStream) method before calling signDigitalSignature() on the PdfDocument.

Can IronPDF handle both approval and certification signatures?

Yes, IronPDF supports both approval signatures, which can be sequentially added by multiple parties, and certification signatures, which lock the document according to a specified PdfCertificationLevel.

How do I add a timestamp to a digital signature in IronPDF?

To add a timestamp, configure the PdfSignature with a timestamp URL of a trusted Timestamp Authority and the desired hash algorithm using setTimestampUrl() and setTimestampHashAlgorithm() methods, respectively.

What are the certification levels available in IronPDF?

IronPDF provides three certification levels: NO_CHANGES_ALLOWED, FORM_FILLING, and FORM_FILLING_AND_ANNOTATIONS. These levels control the extent of modifications permitted after certification.

What happens if the Timestamp Authority server is unreachable during the signing process?

If the Timestamp Authority server is unreachable, IronPDF will throw an exception. It is advised to verify network access and the TSA endpoint URL before deploying to production.

How do I certify a document with no changes allowed using IronPDF?

To certify a document with no changes allowed, construct a PdfSignature, set any required metadata, and call pdf.certify() with the PdfCertificationLevel.NO_CHANGES_ALLOWED parameter before applying any approval signatures.

What are the benefits of using digital signatures on PDFs with IronPDF?

Digital signatures ensure the authenticity and integrity of a document by creating a cryptographic identity tied to a private key. They are ideal for contracts, invoices, and legal documents, where tamper evidence and verification are crucial.

What next steps are recommended after setting up digital signatures with IronPDF?

After setting up digital signatures, consider exploring related IronPDF functionalities, such as creating and filling PDF forms, adding annotations, and merging PDFs to enhance your Java PDF workflow.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Version:2026.8just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project