我正在尝试使用iText 7
.
尝试设置字段的值时,我不断收到错误消息。我无法从该方法的文档中找到信息addKid()
。有谁知道如何解决这个错误?
这是我正在使用的代码示例:
PdfTextFormField confField = PdfFormField.createText(pdf);
confField.setFieldName(fieldName);
PdfWidgetAnnotation confCoverAnnot = new PdfWidgetAnnotation(new Rectangle(x, y, width, height));
PdfWidgetAnnotation confAnnot = new PdfWidgetAnnotation(new Rectangle(x2, y2, width2, height2));
for (int i = 1; i<= numPages; i++) {
switch(i) {
case 1:
pdf.getPage(i).addAnnotation(confCoverAnnot);
break;
default:
pdf.getPage(i).addAnnotation(confAnnot);
break;
}
}
/*
Trying to have two different annotations reference the same field value.
Upon using the `setValue()` method, I get: object.must.be.indirect.to.work.with.this.wrapper
Any way to get this to work properly?
*/
form.addField(confField);
confField.addKid(confCoverAnnot);
confField.addKid(confAnnot);
if (value.equals("") != true) {
confField.setValue(value); //error here
}