XFA フォームの操作
Contents
[
Hide
]
XFA フォームは標準の AcroForms に変換でき、通常の PDF フォーム API で処理できるようになります。
動的 XFA フォームを AcroForm に変換
- ソース PDF の Document を開いてください。
- ドキュメントの Form にアクセスし、必要な FormType プロパティを設定してください。
- 更新した 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 を使用して変換
- ソース PDF の Document を開いてください。
- ドキュメントの Form にアクセスし、必要な
ignoreNeedsRenderingおよび FormType プロパティを設定してください。 - 更新した 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());
}
}