iText 7.0.0
Fields ディクショナリを直接操作せずに iText7 でフィールド階層を構築する方法はありますか? PdfFormField には setParent / addKid メソッドがありますが、生成できる AcroForm.addField と setParent/addKid の正しい組み合わせ/シーケンスが見つかりませんでした (うまくいけば、この構文は理にかなっています):
/Fields [(
/T root 1 0 ("empty" field)
/Kids [(
/T child 2 0 ("empty" field)
/Parent 1 0
/Kids [(
/T text1 (text widget)
/FT Txt
/Type /Annot
/Subtype /Widget
/Parent 2 0
)]
)]
)]
つまり、という名前のフィールドroot.child.text1
私が来た最も近いもの(特定のindirectRefシナリオでは機能しません)は
PdfFormField root = PdfFormField.createEmptyField(doc);
root.setFieldName("root");
form.addField(root, null);
PdfFormField child = PdfFormField.createEmptyField(doc);
child.setFieldName("child");
form.addField(child, null);
root.addKid(child);
PdfTextFormField text1 = PdfFormField.createText(doc, new Rectangle(100, 700, 200, 20), "text1", "");
// any rendered field needs to be added to the form BEFORE parent
// is set, otherwise an exception is thrown in processKids()
form.addField(text1);
child.addKid(text1);
// cleanup the Fields dict
PdfArray rootFields = form.getPdfObject().getAsArray(PdfName.Fields);
rootFields.remove(text1.getPdfObject());
rootFields.remove(child.getPdfObject());