Get information from a form

This is a code example of iText PDF, discover more.

6th November 2015

Switch code for this example
 * Example written by Bruno Lowagie in answer to:
 * Given a check box in a form, how do we know which values to use in setField?
package sandbox.acroforms;

import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;


public class CheckBoxValues {

    public static final String SRC = "../sandbox/resources/pdfs/datasheet.pdf";
    public static final String FIELD = "CP_1";
    public static void main(String[] args) throws IOException {
        CheckBoxValues app = new CheckBoxValues();
        System.out.println(app.getCheckboxValue(SRC, FIELD));
    public String getCheckboxValue(String src, String name) throws IOException {
        PdfReader reader = new PdfReader(SRC);
        AcroFields fields = reader.getAcroFields();
        // CP_1 is the name of a check box field
        String[] values = fields.getAppearanceStates("CP_1");
        StringBuffer sb = new StringBuffer();
        for (String value : values) {
        return sb.toString();



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