Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTextSharp 5.5.6.0 Bug? check box tick mark changes

Tags:

c#

itextsharp

I have an existing PDF that I am filling in programmatically (C#).

There are check boxes on the form. In build 4.4.x they rendered a check mark when selected. In build 5.5.5.0 and 5.5.6.0 they are now a cross symbol. The document has PdfVersion of 54 '6'.

I have tried:

SetFieldProperty(fieldname, "checkboxtype", RadioCheckField.TYPE_CHECK, null);

but with no luck.

Also I searched for the potential property list, but cannot seem to find a list of valid string values. Is the iText in Action -> Table 8.3 a complete listing?

like image 314
Stevec Avatar asked May 12 '15 23:05

Stevec


2 Answers

I was having this exact problem. If I manually filled out the PDF form in Adobe it put checkmarks, but if I used iTextSharp, it put crosses. What worked for me to make iTextSharp put checkmarks was using:

SetField("checkbox name", "Yes", true);

The 'true' at the end changed it from a cross to a checkmark. Hope that helps you.

like image 175
Tyler Jennings Avatar answered Nov 02 '22 01:11

Tyler Jennings


As other comments have stated, casting cannot be done on a PDF that was already created.

On the other hand, if you are filling out an existing PDF you can still change the check type of a CHECKBOX using Adobe Acrobat Pro. First, open the pdf with Adobe Acrobat Pro then click Tools-> Forms-> Edit then double click the field to open up the Field Properties, in this case Check Box Properties, then Options and change the "Check Box Style" to whatever you want.

In your code, use the lines:

AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("checkbox name", "Yes", true);

The "true" flag makes it so that iTextSharp uses the check box style that you chose when using Adobe Acrobat Pro.

like image 1
cgalindo Avatar answered Nov 02 '22 01:11

cgalindo