# Working with Multi-Page Documents

When creating templates for multi-page documents, it is necessary to define unique anchors, which will be searched for only in a specific type of document. For example, in a UPD document, the term invoice may appear, so this term should not be used as an anchor for either UPD or Invoice.

When working with a multi-page document, it sometimes happens that one document spans several pages.

For each type of document, a separate template must be created (for example, 1 — Torg12, 2 – Invoice, 3 – UPD), and all types of documents should be specified in the variable values. The variable type should be selected as List.

![](https://sherparpa.ru/wp-content/uploads/2023/11/image13-547w129h.png)

Next, specify the path to the template file:

![](https://sherparpa.ru/wp-content/uploads/2023/11/image14-499w232h.png)

Specify the Page Number – 1, so that recognition starts from the first page. Also, specify the path to the file.

![](https://sherparpa.ru/wp-content/uploads/2023/11/image15-253w217h.png)

**Ending Robot Work Upon Error**

At the end of the template creation process, it is necessary to outline the further scenario for its recognition and output of results.

If the robot is unable to recognize the document, the scenario may be stopped. To do this, in Sherpa Designer, add the "End" block. You can also add a "Log" block to record the error in the log.

![](https://sherparpa.ru/wp-content/uploads/2023/11/image16-209w48h.png) ![](https://sherparpa.ru/wp-content/uploads/2023/11/image17-237w56h.png)

Recognition errors may occur when none of the templates fit or when there are no documents left for recognition.

If there are multiple documents in the PDF file, and one of the document types is unknown to the robot (i.e., there is no template for this document type), the robot will skip this document and will only recognize those documents for which templates exist.

**Finding the Second and Subsequent Documents in a Multi-Page File**

After one of the templates has been recognized in a multi-page document, it is necessary to make changes to the specified index (add), so that further recognition starts not from the next page, but after the found document.

Since there is a parameter CountPage in the attributes, which corresponds to the number of pages involved in recognition by the template, to continue the recognition process, this parameter needs to be added to the index.

Thus, if the first document occupying several pages has been recognized in the multi-page document, by adding the CountPage parameter, further recognition will begin from the page following the recognized document.

![](https://sherparpa.ru/wp-content/uploads/2023/11/image18-596w145h.png)

After that, configure the scenario for re-recognition of the document.

![](https://sherparpa.ru/wp-content/uploads/2023/11/image19-429w208h.png)
