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

# Before matching

> Control which sections and Document Definitions are matched on each page with the Before matching script, speeding up matching and skipping recognition.

## What it does

The handler of this event allows you to control what sections or Document Definitions will be matched on each subsequent page and specify the matching order.

With this script you can accelerate matching the Document Definition if sections to be matched are known in advance. For example:

* it is known that only the first page of the batch may have the Document Definition "Contents".
* it is known that the given page belongs to a particular section type.
* the order of sections in the documents is known.

The script allows you to disable recognition of document after a Document Definition is matched. For this, set the **IMatchingInfo.NeedRecognition** parameter to **false**. It can be useful if field values are supposed to be entered manually.

It is also possible to mark the page as an annex page which does not need recognition. For this, it is necessary to specify an empty list of sections and set the **IMatchingInfo.ForceMatch** parameter to **true**.

## When it is launched

The script is launched prior to matching sections on each subsequent page.

## Parameters

| **Name**  | **Type**                                                       | **Access**                                                                                                                             | **Description**                                           |
| --------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| Document  | [IDocument](/flexi-capture/appendix/scripts/idocument)         | Read-only. Internal[\*](/flexi-capture/appendix/scripts/before-matching#asterisk) fields of batch documents and pages are unavailable. | The document whose pages are being analyzed               |
| Matching  | [IMatchingInfo](/flexi-capture/appendix/scripts/imatchinginfo) | Read/write                                                                                                                             | The object that specifies some of the matching parameters |
| PageIndex | int                                                            | Read-only. Internal[\*](/flexi-capture/appendix/scripts/before-matching#asterisk) fields of batch documents and pages are unavailable. | The index of the document page to be analyzed             |

<a id="asterisk" />\* - The internal field requires loading the object into memory.

<Note>
  It is also possible to specify Document Definitions and sections to be matched by using named registration parameters. For details, see [Registration Parameters](/flexi-capture/project-settings/reg-params).
</Note>
