Check if data isn’t null (parse form is supported for the document);
Iterate over field data to obtain form data.
The following example shows how to parse a form of the document:
// Create an instance of Parser class
try(Parserparser=newParser(Constants.SampleFormsPdf)){// Extract data from PDF document
DocumentDatadata=parser.parseForm();// Check if form extraction is supported
if(data==null){System.out.println("Form extraction isn't supported.");return;}// Iterate over extracted data
for(inti=0;i<data.getCount();i++){System.out.print(data.get(i).getName()+": ");PageTextAreaarea=data.get(i).getPageArea()instanceofPageTextArea?(PageTextArea)data.get(i).getPageArea():null;System.out.println(area==null?"Not a template field":area.getText());}}
More resources
Advanced usage topics
To learn more about document data extraction features and get familiar how to extract text, images, forms and more, please refer to the advanced usage section.
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: