public class DocumentData extends Object implements Iterable<FieldData>
FieldData objects which contain field data from document.
An instance of DocumentData class is used as return value of Parser.parseByTemplate(Template) and Parser.parseForm() methods. See the usage examples there.| Constructor and Description |
|---|
DocumentData(Iterable<FieldData> fields)
Initializes a new instance of the
FieldData class. |
DocumentData(Template template,
Iterable<FieldData> fields)
Initializes a new instance of the
DocumentData class with the source template. |
| Modifier and Type | Method and Description |
|---|---|
FieldData |
get(int index)
Gets the field data by an index.
|
int |
getCount()
Gets the total number of the fields data.
|
List<FieldData> |
getFieldsByName(String fieldName)
Returns the collection of field data where the name is equal to
fieldName. |
Template |
getTemplate()
Gets the template that produced this document data.
|
Iterator<FieldData> |
iterator()
Returns an iterator over the elements in this list in proper sequence.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic DocumentData(Iterable<FieldData> fields)
FieldData class.fields - The collection of fields data.public DocumentData(Template template, Iterable<FieldData> fields)
DocumentData class with the source template.template - The template that produced these fields. May be null when the data was not produced by a template (e.g. parseForm).fields - The collection of fields data.public Template getTemplate()
When the data was produced by an automatic template-collection selection (see
Parser.parseByTemplate(com.groupdocs.parser.templates.TemplateCollection, com.groupdocs.parser.options.ParseByTemplateOptions)),
this is the selected template. null when the data was not produced by a template.
Template, or null.public int getCount()
public FieldData get(int 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());
}
}
index - The zero-based index of the field.FieldData class.public List<FieldData> getFieldsByName(String fieldName)
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.
fieldName - The name of the field.FieldData objects; empty collection if no field data is found.Copyright © 2026. All rights reserved.