Here is a sample Java program that can load a dynamic XFA form, fill in data from an XDP or XML file and then saved the filled form.

This sample is using Qoppa’s PDF library jPDFFields. It could be simply adapted to use jPDFProcess library by replacing PDFFields with PDFDocument.

import com.qoppa.pdfFields.PDFFields;
 
public class ImportInXFAForm
{
    public static void main (String [] args)
    {
        try
        {
            // Load the xfa dynamic form
            PDFFields pdfDoc = new PDFFields ("C:/test/purchase_order.pdf", null);
 
            // Import the fields data in XDP format
            pdfDoc.importXDP("C:/test/purchase_order_data.xdp");
 
            // Save the filled form 
            pdfDoc.saveDocument("C:/test/purchase_order_filled.pdf");
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
    }
}

Download
Download Sample XFA Form
Download Sample XFA Data in XDP Format
Download Sample XFA Dynamic Form Filled

Dynamic Forms have Dynamic Layout
These kind of forms are called dynamic because their layout can change based on the data present in the form. So for instance, when opening the filled XFA dynamic form above in Adobe Reader, one can notice that:

  • the “order” Table has grown and a second page was added to the PDF dynamically to accommodate the size of the table and the number of rows.
  • the Comments field has expanded so the all the imported text from the comments field is visible.