This precise tutorial elaborates the details on how to add digital signature to PDF in Java. It covers all the basic details about how using Java sign PDF document with a certificate file. Moreover, we do not need to install any other tool to integrate the PDF signing feature in PDF processing applications.
Steps to Add Digital Signature to PDF in Java
- Add the reference to the Aspose.PDF for Java library in the project for digitally signing a PDF file
- Load the target PDF file into the Document class object for signing it
- Initialize PKCS7 class object to load the input certificate file
- Specify Rectangle coordinates and set the appearance image for the signature
- Sign the document with certify method and save the output file
These steps summarize how to add a digital signature in PDF using Java. You can control the page number as well as the rectangular coordinates to place the digital signatures. Likewise, you can control signature appearance like the image, reason, contact details, etc. while signing a PDF document.
Code to Add Digital Signature to PDF in Java
This code sample in Java sign PDF with certificate where we need to specify the password for the PFX certificate file. Moreover, this code can be improvised as per your needs. For instance, you can decide to load an input PDF file to add a digital signature to it or initialize a blank document to work with it and sign it using the PdfFileSignature class.
In this article, we have explored adding digital signatures to PDF in Java. Whereas, if you want to understand the process to protect PDF with a password, please head to the article on how to protect PDF with Password in Java.