5

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?

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
Stevec
  • 51
  • 3
  • Going from 4.4.x to 5.5.6 is a giant leap. Many changes are to be expected. – mkl May 13 '15 at 04:10
  • The code snippet in the question isn't supposed to work: there is no field property `"checkboxtype"`. Changing the checkboxtype involves changing the "on" and "off" appearances of the check box. I think the diagnosis is wrong. I think something else is at play; e.g. is the `Needappearances` value set in the PDF form? Actually: I think that iText 5.5.6 is showing the correct behavior whereas iText 4.4.x is doing it wrong. We should see the form to be sure. – Bruno Lowagie May 13 '15 at 06:26
  • Thanks for the response ! Unfortunately I can't post the form on a public forum (I could email to you). I am programmatically controlling the On/Off appearance of the tick mark. When the form is edited manually it is the correct "check" tickmark....so you comment is that the default symbol is a function of the form itself (is it dependent on an embedded font? I'll check the Needappearances value. The code and the form didn't change just the iText version. – Stevec May 16 '15 at 03:00
  • iTextSharp 4.4.x does not exist and has never existed. Perhaps you are confusing with 4.2.0? – Amedee Van Gasse Mar 04 '16 at 00:53

3 Answers3

4

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.

Tyler Jennings
  • 8,761
  • 2
  • 44
  • 39
1

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.

cgalindo
  • 19
  • 3
  • *"You cannot programmatically change a "Check Box Style" of an already created pdf using iTextSharp."* - that's clearly wrong. You probably don't have a nice high-level method for it but you can use the low-level api here which allows arbitrary changes. – mkl Apr 19 '19 at 11:06
  • What is an example of this using iTextSharp? – cgalindo Apr 19 '19 at 23:07
  • As Bruno said in a comment to the original question, *Changing the checkboxtype involves changing the "on" and "off" appearances of the check box*. So all you need to do is (ex)change the appearance streams of the checkbox widgets. – mkl Apr 22 '19 at 10:24
0

iTextSharp to get "Tick Mark" in PDF file. Please try the below one

form.SetField("Check Box1", "Yes",true);
LarsTech
  • 80,625
  • 14
  • 153
  • 225
jeg
  • 1
  • 1