> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Document Definitions

A Document Definition describes the location of document elements and indicates the fields to be used in data extraction.

Document Definitions can be obtained in one of the following ways:

* A Document Definition may be part of an ABBYY FlexiCapture 12 project. When creating a Document Definition in ABBYY FlexiCapture, field properties are specified along with their range of values. Data export settings are also configured.
* A Document Definition may be created in the project by calling the [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-addnew.md) method of the [**DocumentDefinitions**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions.md) object.
* A Document Definition may be loaded from a file to the project with the help of the [**LoadFromFile**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-loadfromfile.md) method of the **DocumentDefinitions** object.

Below are detailed instructions for creating Document Definitions using ABBYY FlexiCapture SDK.

A Document Definition can comprise any number of sections. The section of a Document Definition is a set of pages (or a single page) and fields on these pages which corresponds to a logically complete part of a document. Using ABBYY FlexiCapture SDK, you can create a simple Document Definition, which consists of a single section, or a compound Document Definition with several sections.

## Creating a compound Document Definition

1. [Open the project](https://docs.abbyy.com/flexi-capture/sdk/guided-tour/engine-openingproject.md) and get the collection of Document Definitions of the project.
2. Create an empty Document Definition using the [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-addnew.md) method of the **DocumentDefinitions** object.
3. Switch the Document Definition to editing mode by calling the [**CheckOut**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-checkout.md) method of the **DocumentDefinitions** object.
4. Set the language to be used with this Document Definition during recognition. Use the **DefaultLanguage** property of the created [**DocumentDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinition.md) object.
5. Set the default text type using the **DefaultTextType** property of the **DocumentDefinition** object.
6. Create a new fixed section from an XFD file:
   1. Add the new section into the Document Definition with the help of the [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions-addnew.md) method of the [**SectionDefinitions**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions.md) object.
   2. Load the XML Form Definition into this new section using the [**LoadXFDDescription**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition-loadxfddescription.md) method of the new [**SectionDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition.md) object.
7. Create a new flexible section from an AFL file:
   1. Add the new section into the Document Definition with the help of the [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions-addnew.md) method of the [**SectionDefinitions**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions.md) object.
   2. Load ABBYY Flexible Layout into this new section using the [**LoadFlexibleDescription**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition-loadflexibledescription.md) method of the new [**SectionDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition.md) object. You can also load it from stream using [**LoadFlexibleDescriptionFromStream**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition-loadflexibledescriptionfromstream.md) method.
8. Create a new section with necessary fields from scratch.
   1. Add the new section into the Document Definition with the help of the [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions-addnew.md) method of the [**SectionDefinitions**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinitions.md) object.
   2. Get the collection of fields of the section using the [**Fields**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition.md#fields) property of the **SectionDefinition** object.
   3. Add new field definitions by calling [**AddNew**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinitions-addnew.md) method of the [**FieldDefinitions**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinitions.md) object.
9. Repeat the steps 6-8 if necessary.

## Setting additional properties

To improve the quality of recognition, you may configure the types of field values:

1. For a section of the created Document Definition, get a set of its field definitions. Use the **Fields** property of the [**SectionDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition.md) object.
2. Find the necessary field definition. Note that fields may be simple (without an internal structure), or composite (such as a table field where each cell can be viewed as a separate subordinate field of the table). Therefore, to iterate through all field definitions of the section definition, it is not enough to iterate through all the elements of the **ISectionDefinition::Fields** collection, you should also check if the field is composite and access its child fields (see the [**IFieldDefinition::Children**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinition.md#children) property).
3. Set the type of the field value using the [**ValueType**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinition.md#valuetype) property of the [**FieldDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinition.md) object.

Sometimes it is not convenient to specify any particular type of field value as this restricts field values. E.g. if a user enters incorrect data into such a field, this will produce an error. To avoid specifying some special type of field value, you may create a special language for the field and set its parameters for recognition of a specific text. For details see [Setting up Recognition Languages](https://docs.abbyy.com/flexi-capture/sdk/guided-tour/settinguprecognitionlanguages.md).

You may also set other recognition parameters using the [**IFieldDefinition::RecognitionParams**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/fielddefinition.md#recognitionparams) property.

## Checking Document Definitions

Check the created Document Definition. Use the **Check** methods of the [**DocumentDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinition.md) object and [**SectionDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/sectiondefinition.md) subobjects. These methods check a Document Definition for errors. If there are errors, the lists of errors are available in the **Errors** properties of the **DocumentDefinition** object and **SectionDefinition** subobjects.

## Saving Document Definitions

## If there are no errors after checking the Document Definition, call the [CheckIn](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-checkin.md) method of the DocumentDefinitions object to save the Document Definition with all the properties you have set. Or you can use the [UndoCheckout](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinitions-undocheckout.md) method of the DocumentDefinitions object to discard all the changes that you made.

## See also

[**DocumentDefinition**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/documentdefinition.md)
