We are upgrading Java code from itext5 to itext7, but there seems to be a lot of changes we need to make. For example, we have a pdf template with some text fields and our Java code is to fill values for those fields. A code snippet in itext5 looks like:
stamper = new PdfStamper(template, filledPdf);
AcroFields form = stamper.getAcroFields();
XfaForm xfa = form.getXfa();
xfa.fillXfaForm(inputXmlDataFile);
returnPdf = filledPdf.toByteArray();
After upgrading to itext7, the approach above no longer works. Instead, we could use the code like below to populate fields:
pdfDoc = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
Map<String, PdfFormField> fields = form.getAllFormFields();
// loop all the fields to set the value
fields.forEach(field -> {
// get the value and set for each field
});
The new approach works fine until there is a repeatable row field inside a table in the template. The call getAllFormFields() will only return the fields for one row, since there is only one row defined in the pdf template. How should the Java code populate values for multiple rows in the table? I was trying to find a sample code to do that but could not. Any suggestion would be greatly appreciated!
Thanks!
I tried the old approach of creating a xml file to populate the data and it does not work (none of the values is populated).
I am expecting the new itext7 code could populate multiple rows inside a table predefined in the original pdf template.