Are you using data signatures or document signatures?
From: Cosmin Ciuraru [mailto:cosmin.ciur...@gmail.com]
Sent: Tuesday, May 03, 2011 5:40 AM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] iText fill XFA Form and Digital signing
Hello,
I have created a PDF document, with LiveCycle Designer, which contains a
dynamic XFA form, with four text fields and two signature fields. The first
three text fields and one of the signature field are associated into a Form
Object Collection, with the 'Lock Fields After Signing' option on. The fourth
text field and the second signature field are associated into another Form
Object Collection, with the 'Lock Fields After Signing' option on. The first
three text fields are completed by the users and signed by them, filling the
first signature field, in the same collection. I would like to use iText in
order to fill in the fourth text field and add my own signature, in the second
signature field.
In order to fill the fourth text field, I use the methods:
public void readXfaData(String src, String dest) throws IOException,
TransformerFactoryConfigurationError, TransformerException,
ParserConfigurationException, SAXException {
FileOutputStream os = new FileOutputStream(dest);
PdfReader reader = new PdfReader(src);
XfaForm xfa = new XfaForm(reader);
xfa.findDatasetsNode("TextField4").setTextContent("MyTest");
Node data = xfa.getDatasetsNode();
DOMSource source = new DOMSource(data);
Transformer tf=
TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
tf.transform(source, new StreamResult(os));
reader.close();
}
public void fillPdf(String src, String xml, String dest)
throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream(dest),
'\0', true);
AcroFields form = stamper.getAcroFields();
XfaForm xfa = form.getXfa();
xfa.fillXfaForm(new FileInputStream(xml));
stamper.close();
}
and call them like this:
readXfaData(RESOURCE, XMLDATA);
fillPdf(RESOURCE, XMLDATA, RESULT);
where:
RESOURCE - the document received from the users, with the three fields
filled and signed
XMLDATA - the data in the form
RESULT - the pdf file with the fourth text field filled in
After this operation, if I check out the generated XML file, I see that the
file contains the value I want to insert. Also, the PDF file contains the
value. The user signature is invalidated with the message 'At least one
signature is invalid.'. If I click the signature panel, a pop up windows
displays the message 'dataModel does not have a method 'clone''. If I click
OK, the side bar won't show me any information about the digital signature.
If I go on and sign the document, with the method:
public void signPdfSecondTime(String src, String dest)
throws IOException, DocumentException, GeneralSecurityException {
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("/path/to/pkcs12/id.p12"),
"****".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias,
"pass".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader(src);
FileOutputStream fout = new FileOutputStream(dest);
PdfStamper stp = PdfStamper.createSignature(reader, fout,
'\0',null,true);
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null,
PdfSignatureAppearance.WINCER_SIGNED);
// comment next line to have an invisible signature
sap.setVisibleSignature("form1[0].form[0].SignatureField2[0]");
stp.close();
}
it also tells me that at least one signature is invalid, it brings the same pop
up message and still doesn't display the signature panel information. If I
click the second signature, I just added, it tells me is valid. If I click the
first signature and in the 'Document tab', I select 'Compute Modifications
List', it also brings up the pop up message.
I guess the problem is with the way I fill in the fourth text field.
Please, do you have any suggestions?
Thank you!
Regards,
Cosmin
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php