Using Qoppa’s PDF library products, jPDProcess and jPDFSecure, it is possible to add a Document Time Stamp (DTS added in PDF 2.0) to a PDF document.
Here is a sample java program that does so.
PDFDocument doc = new PDFDocument(in, null); // Invisible signature field SignatureField field = doc.getPage(0).addSignatureField("Signature1", new Rectangle2D.Double(0, 0, 0, 0)); // pass in credentials for your time stamp server TimestampServer server = new TimestampServer("http://timestamp.digicert.com", "myuser", "mypwd"); server.setLengthEstimate(8000); // Create signing information for this timestamp server SigningInformation signInfo = new SigningInformation(server); // sign the PDF document doc.signDocument(field, signInfo); // save the PDF document doc.saveDocument(out); |
And here is another sample showing how to add a standard digital signature with a time stamp (in this instance a pkcs12 signature) and then a document time stamp to a PDF document. Both signature fields are invisible.
// Load the keystore that contains the digital id to use in signing FileInputStream pkcs12Stream = new FileInputStream("c:/test/ids/myID.p12"); KeyStore store = KeyStore.getInstance("PKCS12"); store.load(pkcs12Stream, "password".toCharArray()); pkcs12Stream.close(); // create a time stamp server object // using your own credentials for the server time stamp TimestampServer server = new TimestampServer("http://timestamp.digicert.com", "myuser", "mypwd"); server.setLengthEstimate(8000); // load PDF document PDFDocument doc = new PDFDocument(in, null); // create an invisible signature field SignatureField normal1 = doc.getPage(0).addSignatureField("Signature1", new Rectangle2D.Double(0, 0, 0, 0)); // create a standard signature info with a time stamp SigningInformation signInfo = new SigningInformation(store, "user", "password"); signInfo.setTimestampServer(server); // add standard signature with time stamp doc.signDocument(normal1, signInfo); // save the PDF doc.saveDocument(out); // reload the document doc = new PDFDocument(out, null); // create a second invisible signature field SignatureField timestamp1 = doc.getPage(0).addSignatureField("Signature2", new Rectangle2D.Double(0, 0, 0, 0)); // create a document time stamp signature info // there is no additional signature information needed // since this is only a document time stamp signature SigningInformation tsaInfo = new SigningInformation(server); // sign the PDF document doc.signDocument(timestamp1, tsaInfo); // save the PDF document doc.saveDocument(out); |