Dear iText Folks,
I've merrily and productively used iText to extract XML from an XFA form
and am pleased with this newfound power. What I'd like to do now is
insert changed XML back into the XFA form. Here's a simple snippet to
illustrate the round trip:
...
PdfReader reader = new PdfReader(sourceBytes);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, outStream);
XfaForm xfaForm = stamper.getAcroFields().getXfa();
Node domDocument = xfaForm.getDomDocument();
// Make a test change to the XML
String oldXml = new String(XfaForm.serializeDoc(domDocument));
String newXml = oldXml.replaceAll("THIS_IS_OLD", "THIS_IS_NEW");
// Sanity check--make sure we're really changing stuff
if(oldXml.equals(newXml)) throw new IllegalStateException();
// Create a new Dom document from the new XML
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setNamespaceAware(true);
DocumentBuilder builder = fact.newDocumentBuilder();
org.xml.sax.InputSource is =
new org.xml.sax.InputSource(new StringReader(newXml));
Document domCoument = builder.parse(is);
// Place the new DOM doc into the XFA form
xfaForm.setDomDocument(domDocument);
xfaForm.setChanged(true);
XfaForm.setXfa(xfaForm, stamper.getReader(), stamper.getWriter());
...
When I run this code and send the outStream to a new file, it runs
without error. But when I open the new PDF, the THIS_IS_OLD value on the
form does not read THIS_IS_NEW. Is there some additional step I must
take to "sync" the XFA with the form's appearance to the enduser?
Any help is much appreciated.
---------
Max Roland Ekstrom
Senior Software Engineer/Project Architect
Office of Administrative Systems
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php