Radio buttons are not showing up the value in Acrobat Reader after the values set programmatically

478 Views Asked by At

I am upgrading com.lowagie:itext:2.1.7 libraries to com.itextpdf libraries.

It is decided not to use com.itextpdf version 5 series (Example, com.itextpdf:itextpdf:5.5.13.2)as it has reached EOL(End Of Life). So the latest iText version 7.x is used.

Since it is not possible to use com.itextpdf.text.* packages anymore as this package is not present in latest library(beyond iText 5), we are using Acroform from iText7 to handle PDF forms.

Now we are facing issues while handling forms. (using Acroform in iText 7).

The issue is that, we have a set of radio buttons in the template(source) PDF.

  1. We read the source PDF using Acroform
  2. Update the radio button value using formField.setValue(value);
  3. Save the PDF to destination file.
  4. Open the destination PDF in Adobe Acrobat Reader
  5. It is seen that the radio button value is not set.
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfButtonFormField;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
...
ByteArrayOutputStream out = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(out);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(byteArrPdfContent)), writer);
PdfAcroForm destForm = PdfAcroForm.getAcroForm(pdfDocument, true);

Map<String, PdfFormField> formFields = destForm.getFormFields();
PdfFormField destForm.getField(currentFieldName);
formField.setValue(value);

Surprisingly, this was working fine with com.lowagie:itext:2.1.7 (with com.itextpdf.text.pdf.AcroFields;)

0

There are 0 best solutions below