Qoppa has 2 Java libraries that can apply signatures to a PDF document: jPDFSecure and jPDFProcess.

To allow signature calculation with external signature appliances such as hardware security modules (HSM), we’ve defined a ContentSigner interface in our API, which allows our libraries to send the PDF content data to be signed externally and then receive the signature hash back.

We’ve implemented the ContentSigner interface for Microsoft Azure. See sample code below which opens a PDF, add a signature field on the first page called “signature” given a rectangular position, creates a SignatureInformation with the AzureContentSigner, sign the document with that SignatureInformation and finally saved the file.

Here is a snipet of the code to pass on the ContentSigner interface

public static final String APP_ID = "MyAppId";
public static final String APP_PASSWORD ="MyAppPassword";
public static final String KEY_ID = "MyKeyId";
public static final String CERT_ID = "MyCertificateId";
 
public static void main(String [] args) throws Exception
{
 PDFSecure doc = new PDFSecure("C:/test/sample.pdf", null);
 
 Rectangle2D signBounds = new Rectangle2D.Double (36, 36, 144, 48);
 SignatureField signField = doc.addSignatureField(0, "signature", signBounds);
 
 AzureContentSignerSample signer = new AzureContentSignerSample(APP_ID, APP_PASSWORD, KEY_ID, CERT_ID);
 
 SigningInformation signingInfo = new SigningInformation(signer, 
 signer.getCertificate(), signer.getCertificateChain());
 
 doc.signDocument(signField, signingInfo);
 
 doc.saveDocument("C:/test/sample_signed.pdf");
}

Find some sample code below and the implementation of the Azure ContentSigner.

Download Java Sample – Apply Azure Signature to PDF

Download Java Class – AzureContentSigner

Download Full Zip containing all Java sample files and all jars required, including those from the Azure API (as of June 2018, make sure to replace with latest versions of these jars).