Reputation: 1601
I'm using itext 7.1.9
and I need to create a PDF document with two checkbox fields with the same names.
A have tried it the next way:
PdfFormField field = PdfFormField.createComboBox(pdf, rect, name, value, options);
PdfFormField parent;
if ( (parent = form.getField(name)) != null) {
parent.addKid(field);
parent.setValue(value);
}
but it doesn't work for me. The fields disappeared from the PDF.
Upvotes: 1
Views: 186
Reputation: 180
I used iText version 7.2.0 to create PDF where iText creates two fields with the same name. To see the result use Google Chrome or PDF Studio 2021. For some reason Acrobat doesn't render second field with the same name
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.addNewPage();
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
PdfFormField field1 = PdfFormField.createComboBox(pdfDoc, new Rectangle(50, 730, 100, 20), "name", "value", new String[] {"one", "two"});
PdfFormField field2 = PdfFormField.createComboBox(pdfDoc, new Rectangle(50, 700, 100, 20), "name", "value", new String[] {"one", "two", "three"});
form.addField(field1);
form.addField(field2);
pdfDoc.close();
If you want to create checkbox fields with the same name use PdfFormField#createCheckbox method.
Upvotes: 1