dimanche 18 février 2018

itext 7 (.ET) how to display info in a checkbox field

We are making a program with iText7 under .NET.

We need to incorporate a checkbox field in a PDF file.

Here are specific lines of our program :

var writer = new PdfWriter(cPdfNameOut);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
...
PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true);
...
var table = new Table(new float[] {2.5F, 0.2F, 1.8F, 1.8F, 1.5F });
PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true);
...
Cell cell = new Cell();
...
table.AddCell(cell);
...
string cFieldName = ...;
iText.Kernel.Geom.Rectangle rectangle = ...;
...
PdfButtonFormField nameField = PdfChoiceFormField.CreateCheckBox(document.GetPdfDocument(), rectangle, cFieldName, "Yes", PdfFormField.TYPE_CHECK);
form.AddField(nameField);

Line PdfButtonFormField nameField ... :

  • when we indicate "Yes" as default value, the resulting PDF file reacts as we expect, to know that the check icon is displayed alternatively when we click inside the field.
  • when we indicate "Off" as default value, the check icon is NOT displayed alternatively when we click inside the field, uptil we click outside the checkbox field (then, the checkbox icon can be seen)

How is it possible to make the checkbox field reacts as we expect when the initial value is "Off" ?

Thank you in advance for your answer.




Aucun commentaire:

Enregistrer un commentaire