The simple line in the book, updating XFA is outside the scope.. is true but
a bit frustrating as it a VERY powerful way to fill forms

 

I spent some time investigating VTD-XML as a Java parsing library (there is
also a C++ version) and offer the following as a method of at least getting
to the right place in the XML tree and being able to update values to feed
back into an XFA form. It's in Groovy, but all you Java nuts should have no
problem with this

Anyone with better methods would be glad to hear.

 

 

>> 

import com.ximpleware.VTDGen

import com.ximpleware.VTDNav

import com.ximpleware.XMLModifier

import com.ximpleware.AutoPilot

 

/*

Extract.

myform = '''<xfa:datasets
xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/";>

      <xfa:data>

         <myForm>

            <name_title>Mr</name_title>

            <name_first>John</name_first>

            <name_last>Renfrew</name_last>

         </myForm>

      </xfa:data>

      </xfa:datasets>

'''

*/

 

vg = new VTDGen()

xm = new XMLModifier()

f = new File(src)

fis = new FileInputStream(f)

b = new byte[(int) f.length()]

fis.read(b)

vg.setDoc(b)

vg.parse(true)

vn = vg.getNav()

ap = new AutoPilot(vn)

 

ap.selectElementNS("http://ns.adobe.com/xdp/";, 'xdp:xdp')

xm.bind(vn)

 

if (vn.toElement(VTDNav.FIRST_CHILD, "config")){ 

   if (vn.toElement(VTDNav.NEXT_SIBLING , "template")){ 

      if (vn.toElement(VTDNav.NEXT_SIBLING , "xfa:datasets")){ 

         if (vn.toElement(VTDNav.FIRST_CHILD,"xfa:data")){

            if (vn.toElement(VTDNav.FIRST_CHILD,"myForm")){

                 if (vn.toElement(VTDNav.FIRST_CHILD,"name_title")) {

                  i = vn.getText()

                  if (i!=-1){

                     xm.updateToken(i,"Master")

                     xm.updateElementName("name_status")

                     //to change next element value or name need to navigate
with vn.toElement(4)

                     //vn.toElement(4)

                     //i = vn.getText()

                     //xm.updateToken(i, value)

                  }

                }

            }

         }

      }

   }

}

 

xm.output(new FileOutputStream(dest))

 

/*

OUTPUTS

...

<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/";>

   <xfa:data>

      <myForm>

         <name_status>Master</name_status>

         <name_first>John</name_first>

         <name_last>Renfrew</name_last>

*/

 

All you have to do then is open in Acrobat Pro and save as

 

john renfrew 

Right Way Up 

 

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
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

Reply via email to