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

# AddImageFile Method of the FRDocument Object

This method opens a specified image file and adds the pages corresponding to the opened file to a document.

## Syntax

### C++

```cpp theme={null}
HRESULT AddImageFile(
  BSTR               ImageFileName,
  IPrepareImageMode* PrepareMode,
  IIntsCollection*   PageIndices
);
```

### C\#

```csharp theme={null}
void AddImageFile(
  string           ImageFileName,
  IPrepareImageMode PrepareMode,
  IIntsCollection   PageIndices
);
```

### Visual Basic .NET

```vb theme={null}
Sub AddImageFile( _
  ImageFileName As String, _
  [PrepareMode As IPrepareImageMode = Nothing], _
  [PageIndices As IIntsCollection = Nothing] _
)
```

## Parameters

ImageFileName

\[in] This variable contains a full path to the image file to open.

PrepareMode

\[in] This parameter refers to the [PrepareImageMode](/fine-reader/engine/api-reference/image-related-objects/prepareimagemode) object which specifies how an image will be preprocessed during opening.

PageIndices

\[in] This parameter refers to the [IntsCollection](/fine-reader/engine/api-reference/supplementary-objects-and-methods/intscollection) object which specifies the indices of the pages which have to be added to a document. Note that repeated indices are not allowed. To add the same page several times, please call this method several times.<br />This parameter is optional and may be 0, in which case all the pages of the opened file will be added to the document.

## Return values

This method has no specific return values. It returns the [standard return values of ABBYY FineReader Engine functions](/fine-reader/engine/api-reference/return-codes).

## Remarks

* When opening a PDF Portfolio file using this method, its cover is always included in the output file.
* This method may report events to the listeners attached to the IConnectionPointContainer interface of the [FRDocument](/fine-reader/engine/api-reference/document-related-objects/frdocument) object.
* For Linux and Windows:
  * If your license includes the [Office Formats Opening](/fine-reader/engine/licensing/modules#officeformatsopening) module, you may also use this method to open digital documents of [supported formats](/fine-reader/engine/specifications/supported-digital-document-input-formats).
  * Depending on the value of the [IEngine::MultiProcessingParams](/fine-reader/engine/api-reference/engine-object-iengine-interface/properties#multiprocessingparams) property, ABBYY FineReader Engine can distribute opening of multi-page documents to CPU cores.

## Samples

This Windows sample illustrates how to abort adding a page into document in case of its prolonged operating.

<Accordion title="C++ (COM) code">
  ```cpp theme={null}
  // Turn on the timeout in case image loading takes too long
  frDocumentCallback.SetShouldTrackTime( true );
  frDocumentCallback.FlushTimer();
  // Call the AddImageFile method to open an image file
  CheckResult( frDocument->AddImageFile( imageFilePath, 0, pageIndices ) );
  // Turn off the timeout for the subsequent processing
  frDocumentCallback.SetShouldTrackTime( false );
  ...
  // Use the IFRDocumentEvents callback interface for reporting events
  class CFRDocumentCallback: public IFRDocumentEvents {
  public:
      CFRDocumentCallback() : startTime( 0 ) {}
   
      // Implement the IUnknown methods
      ULONG STDMETHODCALLTYPE AddRef() { return 1; }
      ULONG STDMETHODCALLTYPE Release() { return 1; }
      HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppObject );
      HRESULT STDMETHODCALLTYPE OnProgress( IFRDocument* document, int percentage, VARIANT_BOOL* ShouldContinue );
      HRESULT STDMETHODCALLTYPE OnWarning( IFRDocument* frPage, int pageNumber, BSTR recognizerTip, 
          VARIANT_BOOL* ShouldContinue );
      HRESULT STDMETHODCALLTYPE OnPageProcessed( IFRDocument* document, int pageNumber, PageProcessingStageEnum stage );
      void FlushTimer();
      void SetShouldTrackTime( bool _shouldTrackTime );
  private:
      time_t startTime;
      bool shouldTrackTime = true;
  };
  // Call the FlushTimer method to reset the startTime
  void CFRDocumentCallback::FlushTimer() {
      time( &startTime );
  }
  // This callback may be used in other methods, so set shouldTrackTime to FALSE if you does not want to reset the timeout anymore 
  void CFRDocumentCallback::SetShouldTrackTime( bool _shouldTrackTime ) {
      shouldTrackTime = _shouldTrackTime;
  }
   
  // If the difference between current time and "startTime" exсeeds a certain threshold, the process will be aborted. The AddImageFile method passes 0 
  instead of percentage to the OnProgress method
  HRESULT STDMETHODCALLTYPE CFRDocumentCallback::OnProgress( IFRDocument* frDocument, int percentage, 
      VARIANT_BOOL* shouldTerminate )
  {
      if( shouldTrackTime ) {
          time_t currentTime;
          time( ¤tTime );
          double seconds = difftime( currentTime, startTime );
          printf( "%f\n", seconds );
          *shouldTerminate = ( seconds > 100 ? VARIANT_TRUE : VARIANT_FALSE );
      }
      return S_OK;
  }
  ```
</Accordion>

This method is used in the [EventsHandling](/fine-reader/engine/guided-tour/samples#eventshandling) and [Document Comparison](/fine-reader/engine/guided-tour/samples#documentcomparison_linux) code samples and the Windows [Document Comparison](/fine-reader/engine/guided-tour/samples#documentcomparison) demo tool.

## See also

[FRDocument](/fine-reader/engine/api-reference/document-related-objects/frdocument)

[AddImageFileWithPassword](/fine-reader/engine/api-reference/document-related-objects/frdocument/addimagefilewithpassword-method)

[AddImageFileWithPasswordCallback](/fine-reader/engine/api-reference/document-related-objects/frdocument/addimagefilewithpasswordcallback-method)

[AddImageDocument](/fine-reader/engine/api-reference/document-related-objects/frdocument/addimagedocument-method)

[Working with Images](/fine-reader/engine/guided-tour/advanced-techniques/working-with-images)
