Skip to main content
Skip table of contents

How to make a field not required?

I am trying to make a field not required using iText.


I know that I can make a field required using something like below statement:


formFields.setFieldProperty(field, "setfflags", PdfFormField.FF_REQUIRED, null);
Is there anything similar to make an existing field not required?


Posted on StackOverflow on Dec 1, 2014 by user2296988

Please have a look at the “How to find out which fields are required?” question. Is solves the same problem.

Based on your question, I assume that you have an existing PDF where you have required fields. It’s really simple to change the FF_REQUIRED flag in iText 7:

public void manipulatePdf(String src, String dest) throws IOException {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
    PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
    Map fields = form.getFormFields();
    PdfFormField item;
    for (String key : fields.keySet()) {
        item = fields.get(key);
        if (item.isRequired())
                item.setRequired(false);
    }
    pdfDoc.close();
}

As you see, we get the form fields using getFormFields() method, then loop all the fields and (if necessary) apply setRequired() method with the false parameter.

Click How to make a field not required? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.