DocumentData class

DocumentData class

Represents data of the document.

An instance of DocumentData is returned by Parser.parse_by_template and Parser.parse_form. See the usage examples there.

The DocumentData type exposes the following members:

Constructors

Constructor Description
init Initializes a new instance of the DocumentData class.
init Initializes a new instance of the DocumentData class.

Methods

Method Description
get
get_enumerator Returns an iterator for the fields data.
get_fields_by_name Returns the collection of field data where the name is equal to field_name.
get_fields_by_name_file
get_fields_by_name_string
get_int32

Properties

Property Description
count The total number of fields data.
template The template.

Example

from groupdocs.parser import Parser
from groupdocs.parser.templates import Template, TemplateField, TemplateFixedPosition
from groupdocs.parser.data import Rectangle, Point, Size

template = Template([
    TemplateField(
        TemplateFixedPosition(Rectangle(Point(35.0, 135.0), Size(100.0, 10.0))),
        "CompanyName",
    ),
    TemplateField(
        TemplateFixedPosition(Rectangle(Point(440.0, 115.0), Size(110.0, 15.0))),
        "InvoiceNumber",
    ),
])

with Parser("./invoice.pdf") as parser:
    data = parser.parse_by_template(template)
    if data is None:
        print("Parsing by template isn't supported for this format.")
    else:
        for i in range(data.count):
            field = data[i]
            print(f"{field.name}: {field.text}")

See Also