Skip to main content
Skip table of contents

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

When filling in a PDF programmatically, how can I show check marks instead of cross checks?


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(PdfFormField.TYPE_CHECK);
            // Use this method if you changed any field parameters and didn't use setValue
            break;
        case 1:
            checkBox.setCheckType(PdfFormField.TYPE_CIRCLE);
            break;
        case 2:
            checkBox.setCheckType(PdfFormField.TYPE_CROSS);
            break;
        case 3:
            checkBox.setCheckType(PdfFormField.TYPE_DIAMOND);
            break;
        case 4:
            checkBox.setCheckType(PdfFormField.TYPE_SQUARE);
            break;
        case 5:
            checkBox.setCheckType(PdfFormField.TYPE_STAR);
            break;
}
checkBox.regenerateField();

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:

protected void manipulatePdf(String src, String dest) throws Exception {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
    PdfAcroForm.getAcroForm(pdfDoc, true).flattenFields();
    pdfDoc.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.

Click this link if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.