How to find out which fields are required?

I'm starting with new functionality in my android application which will help to fill certain PDF forms. I found out that the best solution will be to use iText library. I can read file, and read Ac

I'm starting with new functionality in my android application which will help to fill certain PDF forms. I found out that the best solution will be to use iText library. I can read file, and read AcroFields from a document but is there any possibility to find out that specific field is marked as required?

Posted on StackOverflow on Feb 17, 2013 by weedget

Please take a look at section 13.3.4 of "iText in Action - Second Edition", entitled "AcroForms revisited". Listing 13.15 shows a code snippet from the InspectForm example that checks whether or not a field is a password or a multi-line field.

With some minor changes, you can adapt that example to check for required fields:

for (Map.Entry entry : fields.entrySet()) {
    out.write(entry.getKey());
    item = entry.getValue();
    dict = item.getMerged(0);
    flags = dict.getAsNumber(PdfName.FF);
    if (flags != null && (flags.intValue() & BaseField.REQUIRED) > 0)
        out.write(" -> required\n");
}


Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

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