> ## 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.

# Sample 4. Step 4: Analyzing the images to determine the order in which the elements should be detected

> Analyze invoice images to plan element detection order, including Header and Footer elements that identify the first and last pages of multi-page documents.

At this stage, you have to establish the following:

* Is there any pattern or method in the arrangement of the fields on the images?
* Which elements can be relied on to look for the data fields?
* In what order should the elements be searched for? (This is important, because at each subsequent step you can only rely on the elements of the previous step.)

Because this is a multi-page document, first establish which objects can be used to identify the first and last pages of the document. These objects can be described by means of special compound Header and Footer elements.

* The Header element must match only the first page of the document.

If a project also contains documents of other types, this element will also be used as an identifier (that is, a unique characteristic identifying this document type).

* The Footer element must match the last page of the document only. Create required subelements in this group to prevent the Footer element from being matched with any other document page.

Once you have analyzed the images, you will notice that:

1. On the first page, there is a group of fields that consists of **InvoiceNumber**, **InvoiceDate**, **DeliveryAddress**. The name of the **InvoiceNumber** field always goes at the beginning of each document, whereas the **InvoiceDate** and **DeliveryAddress** are not always present.
   * The **InvoiceNumber** and **InvoiceDate** fields can be located either to the right of their corresponding names or below them.
   * For **DeliveryAddress**, also look either to the right of or below the corresponding name, after limiting the search area. Additionally, an element is needed to restrict the search area from below.
   * Since on some of the images these fields have no values, you can speed up the matching process by specifying the following condition: do not look for the value of a field if the field's name has not been detected.

2. You can use this group of fields as an identifier for the document. These fields are described as part of a compound Header element named **InvoiceHeader**.

3. The last page of the document has the words **TOTAL AMOUNT MUST**, **Carried over**, **Total CHF**, **TOTAL** below the table. However, these words may also occur elsewhere on the document (for example, in the name or in the body of the table). To find these words, you will need to use additional reference elements (for example, table column names). These reference elements will help restrict the search area.

4. The elements describing the last page of the document will be part of a compound Footer element named **InvoiceFooter**.

5. For the Footer element to match only the last page of the document, it must contain a required element. As the words identifying the last page (see item 3) occur on the last page of each document, make the element that describes them a required element.

6. The table (name it **InvoiceTable**) starts on the first page and ends on the last one. Additionally, the table is always preceded by the column names on the first page. To identify the end of the table (on the last page), use an auxiliary element (for example, the required element from the **InvoiceFooter** group).

   <Info>
     The set of all pages of a document is called a multi-page canvas. A multi-page canvas is formed by joining all the pages of a document, top-down, without any gaps, with the left boundary of all the pages lying on the same axis, which goes through the point (0, 0). The order in which the pages are joined together is determined by the order of the pages in the batch. Therefore, you can only specify the start of the table (its header on the first page) and the end of the table (its footer on the last page). The program will search for the table in the entire document, that is, on the entire multi-page canvas.
   </Info>

7. Look for the name of the company in the **Company** field always on the first page and always in the upper third of the page.

8. The name of the **Total Amount** field is always located on the last page, below the table. The value of the field is located either to the right of the name or below it.
