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

Syntax

C++

HRESULT AddImageFile(
  BSTR               ImageFileName,
  IPrepareImageMode* PrepareMode,
  IIntsCollection*   PageIndices
);

C#

void AddImageFile(
  string           ImageFileName,
  IPrepareImageMode PrepareMode,
  IIntsCollection   PageIndices
);

Visual Basic .NET

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 object which specifies how an image will be preprocessed during opening. PageIndices [in] This parameter refers to the 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.
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.

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 object.
  • For Linux and Windows:

Samples

This Windows sample illustrates how to abort adding a page into document in case of its prolonged operating.
// 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;
}
This method is used in the EventsHandling and Document Comparison code samples and the Windows Document Comparison demo tool.

See also

FRDocument AddImageFileWithPassword AddImageFileWithPasswordCallback AddImageDocument Working with Images