Returns:
int - An integer value that represents the total number of the fields data.
get(int index)
public FieldData get(int index)
Gets the field data by an index.
Iteration via all the fields:
// Print all extracted data
for (int i = 0; i < data.getCount(); i++) {
// Print field name
System.out.print(data.get(i).getName() + ": ");
// As we have defined only text fields in the template,
// we cast PageArea property value to PageTextArea
PageTextArea area = data.get(i).getPageArea() instanceof PageTextArea
? (PageTextArea) data.get(i).getPageArea()
: null;
System.out.println(area == null ? "Not a template field" : area.getText());
}
FieldData class represents field data. Depending on the field PageArea property can contain any
of the inheritors of PageArea class. For example, Parser.parseForm() method extracts only text fields:
// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SampleFormsPdf)) {
// Extract data from PDF document
DocumentData data = 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 (int i = 0; i < data.getCount(); i++) {
System.out.print(data.get(i).getName() + ": ");
PageTextArea area = data.get(i).getPageArea() instanceof PageTextArea
? (PageTextArea) data.get(i).getPageArea()
: null;
System.out.println(area == null ? "Not a template field" : area.getText());
}
}
public List<FieldData> getFieldsByName(String fieldName)
Returns the collection of field data where the name is equal to fieldName .
Find fields by a field name:
// Print prices
System.out.println("Prices:");
for (FieldData field : data.getFieldsByName("Price")) {
PageTextArea area = field.getPageArea() instanceof PageTextArea
? (PageTextArea) field.getPageArea()
: null;
System.out.println(area == null ? "Not a template field" : area.getText());
}
FieldData class represents field data. Depending on the field PageArea property can contain
any of the inheritors of PageArea class. For example, Parser.parseForm() method extracts only text fields.
Parameters:
Parameter
Type
Description
fieldName
java.lang.String
The name of the field.
Returns:
java.util.List<com.groupdocs.parser.data.FieldData> - A collection of FieldData objects; empty collection if no field data is found.
iterator()
public Iterator<FieldData> iterator()
Returns an iterator over the elements in this list in proper sequence.
Returns:
java.util.Iterator<com.groupdocs.parser.data.FieldData> - an iterator over the elements in this list in proper sequence.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.