forms - How to fill XFA from using iText so it is Foxit Reader comptible -


i used examples available on web create application able xml structure of xfa form , set filled. important code looks this:

public void readdata(string src, string dest)         throws ioexception, parserconfigurationexception, saxexception,         transformerfactoryconfigurationerror, transformerexception {     fileoutputstream os = new fileoutputstream(dest);     pdfreader reader = new pdfreader(src);     xfaform xfa = new xfaform(reader);     node node = xfa.getdatasetsnode();     nodelist list = node.getchildnodes();     (int = 0; < list.getlength(); i++) {         if ("data".equals(list.item(i).getlocalname())) {             node = list.item(i);             break;         }     }      transformer tf = transformerfactory.newinstance().newtransformer();     tf.setoutputproperty(outputkeys.encoding, "utf-8");     tf.setoutputproperty(outputkeys.indent, "yes");     tf.transform(new domsource(node), new streamresult(os));     reader.close(); }  public void fillpdfwithxmldata(string src, string xml, string dest)         throws ioexception, documentexception {      pdfreader.unethicalreading = true;     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();     reader.close(); } 

when use fill form: http://www.vzp.cz/uploads/document/tiskopisy-pro-zamestnavatele-hromadne-oznameni-zamestnavatele-verze-2-pdf-56-kb.pdf works fine , can see filled form in acrobat reader. however, if open document in foxit reader see blank form (tested in latest version , 5.x version).

i tried play little bit , got these xfaform(...).getdomdocument() data:

filled acrobat reader: http://pastebin.com/kxkyh9em
filled foxit reader: http://pastebin.com/tiz7emfe
filled itext: http://pastebin.com/ttklmerc
filled foxit reader after fill itext: http://pastebin.com/uuq0js4b

the field filled . possible use itext in way works foxit reader (and xfa signature stays?)

in filled itext example there's superfluous <xfa:data> element:

<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">   <xfa:data>     <xfa:data>       <hoz>         <!-- rest of data here -->       </hoz>     </xfa:data>   </xfa:data>   <!-- data description --> </xfa:datasets> 

this because fillxfaform() method of xfaform expects xml data without <xfa:data> root element. xml data should like:

<hoz>   <!-- rest of data here --> </hoz> 

i see readdata() method extract existing form data including <xfa:data> element:

<xfa:data>   <hoz>     <!-- rest of data here -->   </hoz> </xfa:data> 

stripping outer element should fix problem. example:

xfaform xfa = new xfaform(reader); node node = xfa.getdatasetsnode(); nodelist list = node.getchildnodes(); (int = 0; < list.getlength(); i++) {     if ("data".equals(list.item(i).getlocalname())) {         node = list.item(i);         break;     } } // strip <xfa:data> node = node.getfirstchild();  // transformer code here 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -