XFA フォームの操作

XFA フォームは標準の AcroForms に変換でき、通常の PDF フォーム API で処理できるようになります。

動的 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());
    }
}