When I click on File and Print, the check boxes don't show in the print preview, and also don't print. Why is that?

I am new to iTextSharp, and would appreciate some help. I am creating some checkboxes, an example of the code is below:

PdfFormField checkbox1 = PdfFormField.CreateCheckBox(writer);
checkbox1.SetWidget(new Rectangle(524, 600, 540, 616),
    PdfAnnotation.HIGHLIGHT_INVERT);
checkbox1.ValueAsName = ("Off");
checkbox1.AppearanceState = ("Off");
checkbox1.FieldName = ("UsersNo");
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", chkOff);
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", chkOn);
writer.AddAnnotation(checkbox1);
Everything looks great and is working well, until it comes to printing the PDF. When I click on File and Print, the check boxes don't show in the print preview, and also don't print.

Posted on StackOverflow on Mar 23, 2015 by user1176737

In iText 7 you define a check box like this:

PdfButtonFormField checkField = PdfFormField.createCheckBox(pdfDoc, new Rectangle(524, 600, 16, 16), "UsersNo", "Off", PdfFormField.TYPE_CHECK);

If you look at the source code of the createCheckBox() method:

public static PdfButtonFormField createCheckBox(PdfDocument doc, Rectangle rect, String name, String value, int checkType, PdfAConformanceLevel pdfAConformanceLevel) {
    PdfWidgetAnnotation annot = new PdfWidgetAnnotation(rect);
    PdfButtonFormField check = new PdfButtonFormField(annot, doc);
    check.pdfAConformanceLevel = pdfAConformanceLevel;
    annot.setFlag(PdfAnnotation.PRINT);
    check.setCheckType(checkType);
    //…
    return check;
}

You’ll notice that the PRINT flag is set automatically, so you won’t face with this problem in iText 7.

Click How to make sure a check box is printed? if you want to see how to answer this question in iText 5.