iText pdf library
Website search

How to make sure a check box is printed?

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),
checkbox1.ValueAsName = ("Off");
checkbox1.AppearanceState = ("Off");
checkbox1.FieldName = ("UsersNo");
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", chkOff);
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", chkOn);

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

There are two ways to create a check box.

  1. There is the easy way, using the RadioCheckField class.

  2. There is the hard way, using the PdfFormField class.

For some reason you have chosen the hard way, and you are now complaining that the visibility is set to "Show on screen, not in print" instead of "Show on screen and in print".

  • The former ("Show on screen, not in print") is the default visibility setting when you create a check box the hard way. It corresponds with no flags being set.

  • The latter ("Show on screen and in print") is the default when creating a check box the easy way. In this case, the following flag is set automatically for your convenience.

As you have chosen the hard way to create a check box, you need to add the line that add the "Print flag" to your code yourself:

checkbox1.Flags = PdfAnnotation.FLAGS_PRINT;

Perfect, works a treat, many thanks for that Bruno.


Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now