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

# GetNextImageDocument Method of the IImageSource Interface

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

This method is implemented on the client-side. The method returns the next image document from the image processing queue of the source.

<Note>
  For Windows, this method should be used only if you open images that were already loaded into memory — for example, using the [OpenBitmap](/fine-reader/engine/api-reference/engine-object-iengine-interface/processing-methods/openbitmap-method) or [OpenDib](/fine-reader/engine/api-reference/engine-object-iengine-interface/processing-methods/opendib-method) methods of the [Engine](/fine-reader/engine/api-reference/engine-object-iengine-interface) object. If you get images from files on disk, implement [GetNextImageFile](/fine-reader/engine/api-reference/batch-processor/iimagesource/getnextimagefile-method).
</Note>

An implementation of the GetNextImageDocument method may include time to wait for the next image document. However, we do not recommend implementing long waiting times, as FineReader Engine is not multithreaded. While waiting for the next document, the Engine will not be able to process messages from the recognition processes and receive notifications about page processing completed. If you do need to specify a long waiting time, the GetNextImageDocument method may return 0. In this case, the Engine will continue processing messages from the recognition processes and providing recognized images and after a while will check if the image queue is empty. If the queue is not empty (i.e., if [IImageSource::IsEmpty](/fine-reader/engine/api-reference/batch-processor/iimagesource/isempty-method) returns FALSE), the Engine will call the GetNextImageDocument method again. However, if the GetNextImageDocument method returns 0 and there are no more pages to process, FineReader Engine will return control to the user: the [IBatchProcessor::GetNextProcessedPage](/fine-reader/engine/api-reference/batch-processor/batchprocessor/getnextprocessedpage-method) method will return 0.

* All the [ImageDocument](/fine-reader/engine/api-reference/image-related-objects/imagedocument) objects in the queue must be valid till the end of processing. For correct operation the ImageDocument objects should be created via the [Engine](/fine-reader/engine/api-reference/engine-object-iengine-interface) object. If they are created via the [FRDocument](/fine-reader/engine/api-reference/document-related-objects/frdocument) object an error may occur because of the FRDocument object being destroyed during the call to the GetNextImageDocument method.
* As the method is implemented on the client-side there are the following restrictions:
  * all password-protected files should be opened manually on the client-side;
  * the attributes specified in the [PrepareImageMode](/fine-reader/engine/api-reference/image-related-objects/prepareimagemode) object during the initialization of the [BatchProcessor](/fine-reader/engine/api-reference/batch-processor/batchprocessor) object will not affect the ImageDocument objects in the queue.

## Syntax

### C++

```cpp theme={null}
HRESULT GetNextImageDocument( IImageDocument** Result );
```

### C\#

```csharp theme={null}
IImageDocument GetNextImageDocument();
```

### Visual Basic .NET

```vb theme={null}
Function GetNextImageDocument() As IImageDocument
```

## Parameters

Result

\[out, retval] A pointer to [IImageDocument](/fine-reader/engine/api-reference/image-related-objects/imagedocument)\* pointer variable that provides access to the next image document in the queue.

## Return values

\[C++ only] If this method returns a value other than S\_OK, it indicates that an error occurred on the client-side.

## Remarks

The client implementation of this method must assure that all exceptions thrown inside the method are caught and handled and no exceptions are propagated outside the method. Propagation of an exception outside the method may lead to unpredictable results (such as program termination).

## Samples

<Accordion title="C# code">
  ```csharp theme={null}
  // Sample implementation of a custom image source which maintains a queue of image files
  public class ImageSourceCallback : FREngine.IImageSource
  {
     public ImageSourceCallback( string imageFilesDirectory )
     {
         imageFiles = ImageSourceHelper.LoadFilesNames( imageFilesDirectory );
         nextFileIndex = 0;
     }
     public bool IsEmpty()
     {
         return nextFileIndex >= imageFiles.Length;
     }
     public FREngine.IFileAdapter GetNextImageFile()
     {
         if( !IsEmpty() ) {
             return new FileAdapterCallback( imageFiles[nextFileIndex++] );
         }
         return null;
     }
     public FREngine.IImageDocument GetNextImageDocument()
     {
         ...
     }
     private string[] imageFiles;
     private int nextFileIndex;
  }
  public class FileAdapterCallback : FREngine.IFileAdapter
  {
      ...
  }
  public class ImageSourceHelper
  {
      ...
  }
  ```
</Accordion>

## See also

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

[GetNextImageFile](/fine-reader/engine/api-reference/batch-processor/iimagesource/getnextimagefile-method)

[IsEmpty](/fine-reader/engine/api-reference/batch-processor/iimagesource/isempty-method)

[ImageDocument](/fine-reader/engine/api-reference/image-related-objects/imagedocument)
