Работа с XFA-формами

XFA-формы могут быть преобразованы в стандартные AcroForm, чтобы их можно было обрабатывать с помощью обычных API форм PDF.

Преобразование динамической формы XFA в AcroForm

  1. Откройте исходный PDF в объекте Document.
  2. Получите доступ к форме Form документа и установите необходимые свойства FormType.
  3. Сохраните обновлённый 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());
    }
}

Преобразование формы XFA с ignoreNeedsRendering

  1. Откройте исходный PDF в объекте Document.
  2. Получите доступ к форме Form документа и установите необходимые свойства ignoreNeedsRendering и FormType.
  3. Сохраните обновлённый 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());
    }
}