itext-questions  

Re: [iText-questions] Can't read Acro/XFA fields after offline saving

1T3XT info
Thu, 26 Jun 2008 09:43:36 -0700

Demling, Peter wrote:
> Do you know of a simple way to convert 
> an XFA Form into an AcroForm (to avoid this entire problem)?

Yes.

> Thanks for any tips; and I’m serious about that ice-cream!

I'll give you two answers. The first one is this:

try {
   PdfReader reader = new PdfReader(SAVED_INSTANCE);
   PdfDictionary root = reader.getCatalog();
   PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM);
   acroform.remove(PdfName.XFA);
   AcroFields form = reader.getAcroFields();
   Map<String,Item> fields = form.getFields();
   for (String field : fields.keySet()) {
     System.out.println(field);
     System.out.println(form.getField(field));
   }
   System.out.println(form.getField("MyTextField"));
   reader.close();                                              
} catch (IOException e) {
   e.printStackTrace();
}

As you suggested, I remove the XFA from the form in PdfReader.
That allows me to get the value of the field, but ONLY IF I
USE THE COMPLETE FIELD NAME: form1[0].#subform[0].MyTextField[0]
As you'll find out when running this code form.getField(field)
will return null.

The second answer involves a change in the iText code
(in the library). I'm currently working on that.
If it works, then you won't need the extra lines as
mentioned above. More info about this later on.
-- 
This answer is provided by 1T3XT BVBA

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar