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

# Match a multi-page FlexiLayout

> Match a multi-page FlexiLayout against selected pages: how FlexiLayout Studio pre-recognizes images and finds first and last pages of each document.

To match a FlexiLayout with multiple pages, select the pages in the **Batch** or in the **Image** window and then select **Match FlexiLayout** from the shortcut menu.

## How the FlexiLayout is matched

The application will attempt to match the FlexiLayout as follows:

1. The selected pages are pre-recognized. For each page, the correct orientation is automatically selected based on the pre-recognition language.
2. The first page in the document is detected.
3. The last page in the document is detected.
4. The FlexiLayout is matched with the detected pages.
5. If the FlexiLayout matches the pages, steps 2-4 are performed for the page following the recognized document. If the FlexiLayout does not match, the steps are performed starting with the next page.

The first page in the selection becomes the first page of the document. Next, the program will treat the page following the last page of the previous document as the first page of the new document.

## How the last page of a document is detected

If the FlexiLayout has a set number of pages (the possible number of pages is specified in the [FlexiLayout properties](/flexi-capture/fls/template/ftemplate-properties)), the last page is detected based on the specified number of pages.

If the number of pages may vary in the range \[`MinPages`, `MaxPages`], the program checks whether a **Footer** element is present on the page numbered `MinPages`. If this page contains a **Footer** element, it is deemed to be the last page in the document.

Otherwise, the program checks the following conditions for each subsequent page starting from `MinPages`+1:

1. Whether this page is redundant (its number in the document is greater than the maximum number of pages `MaxPages`).
2. Whether this page contains a **Header** element (this check is performed if the **Footer** element is optional).
3. Whether this page contains a **Footer** element.

If 1 or 2 is true, the preceding page is selected as the last page in the document. If 3 is true, the current page is selected as the last page in the document.
