Search code examples
javapdfitextpdfboxxfa

Need to add xml as XFA to a Jasper Report created pdf


We have a requirement from the courts to submit PDFs in which there is embedded data in xml format. Such that the xml is in an XFA Form in the PDF.

We generate our PDF From Jasper Reports, then generate the xml that we want to add. The generated PDF from Jasper Reports does not have am XFA Form to start importing the xml into.

How do I get the PDF to have an XFA Form created in it so that I can then add the xml of the data to it?


Solution

  • Thanks @BrunoLowagie Unfortunately, the format/rules of what we can use is out of our hands. The PDF is defined by the US Courts. But a co-worker was able to get me a copy of the PDF from the US Courts system that is an "interactive" form that is XFA, so I was able to get the data into the form with all the great work that you guys have done with iText.

    Using the following code. All gotten from your great book.

    AcroFields form = stamper.getAcroFields();
    XfaForm xfa = form.getXfa();
    xfa.fillXfaForm(new ByteArrayInputStream(xmlSchemaStream.toByteArray()));
    

    For anyone reading this in the future. If you wanted to add XFA to your PDF via Java code, the ONLY current solution is Adobe LifeCycle which the app itself is ONLY available on Windows, and you have to install it to get the jar files to use. OH, wait, it gets even better, you include the client jar files into your application. Which means, yes you guessed it, you have to install a Server application and run it in JBoss, Weblogic or Websphere.

    So in the end it will cost way too much money to setup, manage and maintain for something as stupid as adding an XFA form to your PDF.