Why does iText enter a cross symbol when CheckType style is check mark?

Tags: formscheck boxiText 5

I have an existing PDF that I am filling in programmatically (C#). There are check boxes on the form that should be rendered as a check mark when selected, but instead they are visualized as a cross symbol. I 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?

Posted on StackOverflow on Dec 23, 2015 by Stuart Brant

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.

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

Check boxes, highlight fields on
Check boxes, highlight fields on

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

Check boxes, highlight fields off
Check boxes, highlight fields off

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:

Check boxes, flattened form
Check boxes, flattened form

As you can see, the check mark looks like a check mark.