ITextSharp 5.5.6 enters the cross when Check Type Style is a Check Mark

This question was asked earlier ( iTextSharp 5.5.6.0 Error: check the box ), but without an answer, I can not comment, because I'm a new user, I have exactly the same problem.

I have an existing PDF that I fill out programmatically (C #).

There are flags in the form. In assembly 4.4.x, they selected the checkmark when choosing. On lines 5.5.5.0 and 5.5.6.0 they are now cross characters.

Do not think that setting a property will have any effect, as already set in this in pdf. How can I get a tick instead of a cross.

I am using the latest version available from NuGet. You may need to revert to an earlier version if you cannot solve this problem.

+4
c # itextsharp
source share
2 answers

I had a similar problem with iTextSharp 5.5.9 after upgrading from version 4.x. When you check the boxes, the appearance will not be the same as it was set in the original pdf (which was created in acrobat). After over-digging (reference materials are hard to use = /), I finally found an overload for the AcroFields.setField () function, which takes the boolean parameter "saveAppearance". Passing "true" preserves the appearance set in the original pdf.

I was able to dig this information here

+9
source share

You did not mention whether you are creating a form or filling out an existing form, so I will show you both cases.

Create a form:

I adapted CheckboxCell , and I created CheckboxCell2 , which creates six flags using the six available flag 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. Hope your question is not caused by this confusion.

If the Select Fields option of your viewer is enabled, the result is as follows:

enter image description here

If the Select Fields option for your viewer is disabled, the result is as follows:

enter image description here

What is the difference?

In the first screenshot, Adobe Reader is created based on the /CA dictionary /MK entry, which is stored in the annotations of each fieldโ€™s widget. ( /CA defined as the normal widget annotation header that should be displayed when it does not interact with the user.)

The second screen shot displays the appearance, which is stored as the actual appearance of the field. This is the most correct view. Another view (in the first screen shot) is created by the viewer and may look different in different viewers (hence the confusion already mentioned).

Shape smoothing:

When you smooth out a form, you remove all interactivity. In the case of flags, one of the images saved in the PDF file will be saved (and displayed); another will be thrown away.

In CheckBoxFlatten, I smooth out the form we created using CheckboxCell2 :

 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 is as follows:

enter image description here

As you can see, the checkmark looks like a checkmark. I am using the latest version of iText (Sharp): 5.5.8. This behavior is to be expected. As I explained in my commentary on the question โ€œ iTextSharp 5.5.6.0 Bug? Checkmark to checkmark changes, โ€ the behavior of older versions of iText was probably incorrect.

Output:

I proved that you can create a checkmark with a checkmark instead of a cross. I proved that the checkmark is saved when the shape is flattened.

If you do not agree with this, it is now up to you that (1) the checkbox has the correct values /AP and that the entry /CA in the /MK dictionary (if present) matches the look. And (2) that when you select a flag from which (1) is true, this flag miraculously changes from a checkmark to a cross.

If you cannot prove it yourself, you must provide a PDF so that we can test ourselves.

+1
source share

All Articles