package com.qoppa.sample; import java.awt.geom.Rectangle2D; import java.io.FileInputStream; import java.security.KeyStore; import com.qoppa.pdf.SigningInformation; import com.qoppa.pdf.form.SignatureField; import com.qoppa.pdfSecure.PDFSecure; public class SignTwice { private static final String IN = "C:/mydoc.pdf"; private static final String KEYSTORE = "C:/keystore.p12"; private static final String KEYSTORE_PASSWORD = "password"; private static final String ALIAS = "alias"; private static final String ALIAS_PASSWORD = "password"; private static final String OUT = "C:/signedTwice.pdf"; private static final String KEY = "000000000"; public static void main (String [] args) { try { // Load the document PDFSecure pdfDoc = new PDFSecure (IN, null); PDFSecure.setKey(KEY); // Load the keystore that contains the digital id to use in signing FileInputStream pkcs12Stream = new FileInputStream (KEYSTORE); KeyStore store = KeyStore.getInstance("PKCS12"); store.load(pkcs12Stream, KEYSTORE_PASSWORD.toCharArray()); pkcs12Stream.close(); // Create signing information SigningInformation signInfo = new SigningInformation (store, ALIAS, ALIAS_PASSWORD); // Create signature field on the first page Rectangle2D signBounds = new Rectangle2D.Double (36, 36, 144, 48); SignatureField signField = pdfDoc.addSignatureField(0, "signature1", signBounds); // Apply digital signature pdfDoc.signDocument(signField, signInfo); // Save the document & reload the signed document before applying a 2nd signature pdfDoc.saveDocument (OUT); pdfDoc = new PDFSecure(OUT, null); // Create another signature field on the first page signBounds = new Rectangle2D.Double (36, 100, 144, 48); signField = pdfDoc.addSignatureField(0, "signature2", signBounds); // Apply digital signature pdfDoc.signDocument(signField, signInfo); // Save the document that has been signed twice pdfDoc.saveDocument (OUT); } catch (Throwable t) { t.printStackTrace(); } } }