1

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());
4

1 に答える 1

0

以下の方法でアプローチしてみてください。このコードは、少なくとも現在の 7.0.1-SNAPSHOT バージョンでは機能するため、数週間後に予定されている 7.0.1 でも機能します。

各フィールドをフォームに直接追加する必要はありません。仕様によると、ルート フィールド、つまり祖先を持たないフィールドのみをフォームに追加する必要があります。それらの子孫は自動的に考慮されます。

PdfFormField root = PdfFormField.createEmptyField(pdfDoc);
root.setFieldName("root");

PdfFormField child = PdfFormField.createEmptyField(pdfDoc);
child.setFieldName("child");
root.addKid(child);

PdfTextFormField text1 = PdfFormField.createText(pdfDoc, new Rectangle(100, 700, 200, 20), "text1", "test");
child.addKid(text1);

form.addField(root);
于 2016-08-20T13:16:48.863 に答える