4

This question was asked previously (iTextSharp 5.5.6.0 Bug? check box tick mark changes) but with no answer supplied, I cannot comment because I am a new user. I am having exactly the same issue.

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.

Don't think setting the property would have any effect as already set to this in the pdf. How can I get a check mark instead of the cross.

I am using the latest version as available from NuGet. May have to go back to an earlier version if cannot resolve this issue.

Community
  • 1
  • 1
Stuart Brant
  • 155
  • 1
  • 8
  • The previously asked question couldn't be answered because there wasn't sufficient information (assuming that I am looking at the question you are talking about; I've updated your question with a link). Let's hope you can help us help you. I need to see the PDF to see what the appearances stored in the PDF look like. – Bruno Lowagie Dec 23 '15 at 16:29
  • You didn't mention if you are *creating* the form, or if you are *filling out* an existing form. Please clarify. – Bruno Lowagie Dec 23 '15 at 16:41
  • Build 4.4.x? That does not exist. iTextSharp went from 4.2.0 (December 1, 2009) to 5.0.0 (December 9, 2009). – Amedee Van Gasse Dec 23 '15 at 22:25

2 Answers2

11

I was having a similar issue with iTextSharp 5.5.9 after upgrading from a 4.x version. While setting checkboxes the appearance would not be the same as it was set in the original pdf (which was created in acrobat). After excessive digging (the reference materials are difficult to use =/) I finally found an overload for the function AcroFields.setField() that takes a boolean parameter 'saveAppearance'. Passing 'true' preserves the appearance set in the original pdf.

I was able to dig up this information here

Zachary
  • 143
  • 1
  • 8
  • 2
    I spent over weeks to figure why my radio button turned to a DOT while I created the form with a CROSS. this "saveAppearance" saves the day ! – TX T Aug 28 '17 at 16:23
1

You didn't mention if you are creating the form, or if you are filling out an existing form, so I'll show you both cases.

Creating a form:

I've adapted the CheckboxCell example and I've created a CheckboxCell2 example that creates six check boxes using the six available check box types:

switch(i) {
    case 0:
        checkbox.setCheckType(RadioCheckField.TYPE_CHECK);
        break;
    case 1:
        checkbox.setCheckType(RadioCheckField.TYPE_CIRCLE);
        break;
    case 2:
        checkbox.setCheckType(RadioCheckField.TYPE_CROSS);
        break;
    case 3:
        checkbox.setCheckType(RadioCheckField.TYPE_DIAMOND);
        break;
    case 4:
        checkbox.setCheckType(RadioCheckField.TYPE_SQUARE);
        break;
    case 5:
        checkbox.setCheckType(RadioCheckField.TYPE_STAR);
        break;
}

What checkbox_in_cell2.pdf will look like, depends on the behavior of the PDF viewer. This has already caused a lot of confusion. I hope your question isn't caused by this confusion.

If the "Highlight fields" setting of your viewer is on, the result looks like this:

enter image description here

If the "Highlight fields" setting of your viewer is off, the result looks like this:

enter image description here

What is the difference?

In the first screen shot, the appearances are created by Adobe Reader based on the /CA entry of the /MK dictionary that is stored in the widget annotation of each field. (/CA is defined as The widget annotation's normal caption, which shall be displayed when it is not interacting with the user.)

In the second screen shot, the appearance that is stored as the real appearance of the field is shown. This is the most correct appearance. The other appearance (in the first screen shot) is created by the viewer and could look different in different viewers (hence the already mentioned confusion).

Flattening a form:

When you flatten a form, you take away all interactivity. In the case of check boxes, one of the appearances stored in the PDF will be kept (and displayed); the other one will be thrown away.

In the CheckBoxFlatten, I flatten the form we've created using the CheckboxCell2 example:

public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
    stamper.setFormFlattening(true);
    stamper.close();
}

The result looks like this:

enter image description here

As you can see, the check mark looks like a check mark. I'm using the latest version of iText(Sharp): 5.5.8. This is the behavior one should expect. As I explained in my comment on the question "iTextSharp 5.5.6.0 Bug? check box tick mark changes", the behavior of older iText versions was probably wrong.

Conclusion:

I have proven that it is possible to create a check box with a check mark instead of a cross. I have proven that the check mark is preserved when flattening the form.

If you do not agree, it is now up to you to prove that (1) the check box has the correct /AP values and that the /CA entry in the /MK dictionary (if present) corresponds with the on appearance. And (2) that when you select the check box of which (1) is true, that check box miraculously changes from a check mark into a cross.

If you can not prove that yourself, you should provide a PDF so that we can check for ourselves.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165