How to set the export value of a check box?

Tags: formscheck boxiText 7

I need to add a check box to an existing PDF. I also need set the export value of this check box. I saw that I can get the possible values of an existing check box by looking at the appearance dictionary (/AP), but I don't know how to set the export value for a new checkbox.

With export value I mean the value which is marked in the screenshot

Check box export value

Here is my code to create a check box, but the export value is always empty:

PdfFormField checkbox = PdfFormField.createCheckBox(stamper.getWriter());
checkbox.setWidget(fieldVO.rect, PdfAnnotation.HIGHLIGHT_NONE);
checkbox.setFieldName(fieldVO.getNewName());
//TODO set export value
log.info("exportValue is " + fieldVO.getExportValue());
break;
Posted on StackOverflow on Jul 15, 2015 by Al Phaba

In iText7 to create a checkbox you should use:

createCheckBox(PdfDocument doc, Rectangle rect, String name, String value)

The value you insert will be the value of “Export value” you are asking about.

PdfButtonFormField checkBox1 = PdfFormField.createCheckBox(pdfDoc,new Rectangle(10, 650, 40, 20), "checkbox1", "MyExportValue");

By default checkbox has two states: “Off” and “Yes”. In our case instead of “Yes” we will have the “MyExportValue”.

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