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

# BatchProcessor Object (IBatchProcessor Interface)

<Note>
  This object is implemented in FRE for Linux and Windows.
</Note>

This is a processor object which converts input images into the recognized pages ([FRPage](/fine-reader/engine/api-reference/document-related-objects/frpage) objects).

When processor is initialized, asynchronous recognition processes are invoked and configured. Then the processor takes image files from a custom image source. For each page of the image file a new processing task is created, and this task is passed to one of the recognition processes. If all the tasks for one file have been passed for processing, but not all of the recognition processes are occupied, the next image file from the image queue of the source is taken and passed for processing. This is done until the first image page has been converted and passed to the user. Pages are returned to the user in the order they have been taken from the image source.

To organize processing with the Batch Processor, do the following:

1. Implement the [IImageSource](/fine-reader/engine/api-reference/batch-processor/iimagesource) and [IFileAdapter](/fine-reader/engine/api-reference/batch-processor/ifileadapter) interfaces, which provide access to the image source and files in it.
2. \[optional] Implement the [IAsyncProcessingCallback](/fine-reader/engine/api-reference/batch-processor/iasyncprocessingcallback) interface to manage the processing. The methods of this interface allow you to handle errors and/or cancel the processing.
3. Call the [CreateBatchProcessor](/fine-reader/engine/api-reference/engine-object-iengine-interface/creation-methods/createlessobjectgreater-methods) method of the [Engine](/fine-reader/engine/api-reference/engine-object-iengine-interface) object, to receive the BatchProcessor object.
4. Use the PageFlushingPolicy property to set the mode of working with document pages in memory.
5. Call the Start method to initialize the processor and invoke asynchronous recognition processes. You can specify the source of images and processing settings in this method.

* The BatchProcessor object cannot be reused. Repeated calls to the Start method will cause errors.
* Do not create and use several Batch Processors simultaneously, as this may lead to the confusion of processing pages.

6. Call the GetNextProcessedPage method in a loop until the method returns 0, which means that there are no more images in the source and all the processed images have been returned to the user.

<Warning>
  The page returned by the GetNextProcessedPage method exists until the next call of this method. Therefore, if you want to save this page, you must save it using the methods of the [FRPage](/fine-reader/engine/api-reference/document-related-objects/frpage) object or add it to an existing document using the [IFRDocument::AddPage](/fine-reader/engine/api-reference/document-related-objects/frdocument/addpage-method) method BEFORE the next call of the GetNextProcessedPage method.
</Warning>

## Properties

| Name               | Type                                                                                                                                                                                                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Application        | [Engine](/fine-reader/engine/api-reference/engine-object-iengine-interface), [read-only](/fine-reader/engine/guided-tour/advanced-techniques/programming-aspects/working-with-properties#readonly_properties) | Returns the Engine object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| PageFlushingPolicy | [PageFlushingPolicyEnum](/fine-reader/engine/api-reference/enumerations/pageflushingpolicyenum)                                                                                                               | Specifies if the [ImageDocument](/fine-reader/engine/api-reference/image-related-objects/imagedocument) and the [Layout](/fine-reader/engine/api-reference/layout-related-objects/layout) objects for corresponding pages should be unloaded and saved to disk if there are no references to these objects. <Note> In Linux, when this property value is set to PFP\\\_KeepInMemory, the image documents and layouts for unused pages are not saved to disk. </Note> <Note> In Windows, to unload and save to disk the ImageDocument and the Layout objects for separate pages of the document, use the [IFRPage::Flush](/fine-reader/engine/api-reference/document-related-objects/frpage/flush-method) method for the corresponding pages. </Note> This property is PFP\\\_Auto by default. |

## Methods

| Name                                                                                                                 | Description                                                                                                                                           |
| -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [GetNextProcessedPage](/fine-reader/engine/api-reference/batch-processor/batchprocessor/getnextprocessedpage-method) | Provides the background processing until the next recognized image is available.                                                                      |
| [ProcessPageAsync](/fine-reader/engine/api-reference/batch-processor/batchprocessor/processpageasync-method)         | Allows you to repeat processing of a page with another parameters. The page can be pushed at the beginning or at the end of the processing queue.     |
| [Start](/fine-reader/engine/api-reference/batch-processor/batchprocessor/start-method)                               | Prepares the Batch Processor for work. The method invokes asynchronous recognition processes, specifies the source of images and processing settings. |

## Output parameter

This object is the output parameter of the [CreateBatchProcessor](/fine-reader/engine/api-reference/engine-object-iengine-interface/creation-methods/createlessobjectgreater-methods) method of the [Engine](/fine-reader/engine/api-reference/engine-object-iengine-interface) object.

## Samples

<Accordion title="C# code">
  ```csharp theme={null}
  // Create Batch Processor
  FREngine.IBatchProcessor batchProcessor = engine.CreateBatchProcessor();
  FREngine.IFRDocument document = engine.CreateFRDocument();
  // Initialize the processor
  FREngine.IImageSource imageSource = new CImageSource; // the class is implemented by the user
  batchProcessor.PageFlushingPolicy = FREngine.PageFlushingPolicyEnum.PFP_KeepInMemory;
  batchProcessor.Start( imageSource, null, null, null );
  // Start processing
  while( true ) {
   FREngine.IFRPage page = batchProcessor.GetNextProcessedPage();
   if( page == null ) {
    break; // there are no more pages, end of the work
   }
   // do something with the page
   ...
   document.AddPage( page );
  }
  ```
</Accordion>

This object is used in the following code samples: [BatchProcessing](/fine-reader/engine/guided-tour/samples#batchprocessing) and demo tools: [BatchProcessingRecognition](/fine-reader/engine/guided-tour/samples#batchprocessingrecognition).

## See also

[Parallel Processing with ABBYY FineReader Engine](/fine-reader/engine/guided-tour/advanced-techniques/parallel-processing)

[IImageSource](/fine-reader/engine/api-reference/batch-processor/iimagesource)
