Hi,
I created a Blank Signature for a Pdf file. I have generated the signatures using the PdfPKCS7, for testing purpose. In actual scenario, the signature will be generated outside.
When I put the signature back to the Blank Signature field, the code throws NullPointerException while calling preClose() method of SignatureAppearance. I followed the sample given in the howtosign sample in iText.
Below , is the code
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0', null, true);
AcroFields af = stp.getAcroFields();
ArrayList names = af.getBlankSignatureNames();
for (int k = 0; k < names.size(); ++k) {
String name = (String)names.get(k);
log("Signature name: " + name);
PdfSignatureAppearance sap = stp.getSignatureAppearance();
log("creating the visible signature...");
sap.setVisibleSignature(name);
log("creating the pdf dictionary to set the flags...");
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.FT, PdfName.SIG);
dic.put(PdfName.FILTER, new PdfName("SAFE.PPKSF));
dic.put(PdfName.SUBFILTER, new PdfName("adbe.pkcs7.detached"));
dic.put(PdfName.NAME, new PdfString(PdfPKCS7.getSubjectFields((X509Certificate) chain[0]).getField("CN")));
log("setting the dictionary to the appearance...");
sap.setCryptoDictionary(dic);
HashMap exc = new HashMap();
exc.put(PdfName.CONTENTS, new Integer(0x2502));
log("preclosing the appearance");
sap.preClose(exc);
PdfDictionary dic2 = new PdfDictionary();
byte[] out = readFile("signature_pdf.p7s");
dic2.put(PdfName.CONTENTS, new PdfString(out).setHexWriting(true));
sap.close(dic2);
}
stp.close();
any help
regards
Sivakumar.B