Thank you for your responses. I have tried your example but it does the same
thing. Interestingly, the XML does seem to be updated with the updated value
but is not reflected in the actually PDF. After getting the data node:

XfaForm xfa = new XfaForm(reader);
Node node = xfa.getDatasetsNode();
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
  if("data".equals(list.item(i).getLocalName())) {
      node = list.item(i);
      break;
  }
} 

and after updating values within the Node I fill in the XFA:

AcroFields vStamperForm = stamper.getAcroFields();
XfaForm xfaForm = vStamperForm.getXfa();
xfaForm.fillXfaForm(node);

I then write the Node contents to an xml file:

FileOutputStream os = new FileOutputStream("resource/updatedData.xml");
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
tf.transform(new DOMSource(node), new StreamResult(os));

The updatedData.xml file has the updated value to the 'stubborn_field' but
the actual PDF displays an empty stubborn_field value. All other fields are
correctly updated both reflecting in the updatedData.xml and the generated
PDF.




hami wrote
> 
> this example may assist you;
> check if your XFA XML have similar fields with empty and Filled values;
> 
> <form>
> <page1>
> <subform1>
> <name>Pre filled value</name>
> < email / > < ! - - this is empty field ->
> </subform1>
> </page1>
> </form>
> 
> to set the values of empty field you need to do something like this;
> 
> Element el = (Element)nl.item(0);
> if(el.getFirstChild() != null && el.getFirstChild().getNodeValue() !=
> null)
>               el.getFirstChild().setNodeValue(value);  // if field is not 
> empty
> else {
>               el.appendChild(dom.createTextNode(value)); // if field is empty
> }
> 
> or you can do string manipulation by direct replacing the empty "< / emai
> l>" by "< email > Value < email / >"
> 
> hope you find this usefull
> 


--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Field-not-populated-tp4648278p4649603.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
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

Reply via email to