Working with XFA Forms

XFA forms can be converted to standard AcroForms so they can be processed with the regular PDF form APIs.

Convert a dynamic XFA form to an AcroForm

  1. Open the source PDF Document.
  2. Access the document Form and set the required FormType properties.
  3. Save the updated PDF Document.
public static void convertDynamicXfaToAcroform(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        document.getForm().setType(FormType.Standard);
        document.save(outputFile.toString());
    }
}

Convert an XFA form with ignoreNeedsRendering

  1. Open the source PDF Document.
  2. Access the document Form and set the required ignoreNeedsRendering and FormType properties.
  3. Save the updated PDF Document.
public static void convertXfaFormWithIgnoreNeedsRendering(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        if (!document.getForm().getNeedsRendering() && document.getForm().hasXfa()) {
            document.getForm().setIgnoreNeedsRendering(true);
        }
        document.getForm().setType(FormType.Standard);
        document.save(outputFile.toString());
    }
}