跳转到主要内容
这是一个回调接口,用于将来自 FRDocument 对象的事件通知给侦听器。此接口由客户端实现。有关适用于您的开发工具的详细实现建议,请参阅 Working with Connectable Objects。以下是简要说明:
  • C++ 用户需要实现 IFRDocumentEvents 接口,获取一个连接点 (Windows) ,并通过“advise”将实现该接口的对象注册到 FRDocument 对象。由于该接口派生自 IUnknown 接口,因此客户端对象还应实现 IUnknown 的方法。
  • 希望接收来自 FRDocument 对象通知的 Visual Basic 用户应将其声明为 WithEvents,并实现与以下类似的过程:
Public WithEvents doc As FREngine.FRDocument
Private Sub doc_OnPageProcessed(ByVal sender As FRDocument, _
                                ByVal index As Integer, _
                                ByVal stage As PageProcessingStageEnum)
...
End Sub
通过此接口的方法接收通知的对象,可在这些方法的实现中执行以下操作:
  • 报告图像加载、文档分析、识别、合成和导出的完成百分比。
  • 报告已完成的文档分析、识别、合成和导出的相关信息。
  • 在 Windows 中:处理任何系统消息,帮助防止应用程序在长时间操作期间出现无响应。这对于具有用户界面的应用程序会很有帮助。

方法

名称描述
OnPageProcessed向客户端提供有关页面处理完成的信息。
OnProgress向客户端提供有关当前操作 (图像加载、分析、识别等) 大致完成百分比的信息。
OnWarning向客户端提供处理过程中出现的提示和警告信息。

示例

此 Windows C++ 示例演示如何实现一个计时器,在方法调用耗时过长时自动中止处理。
class CFRDocumentCallback: public IFRDocumentEvents {
public:
    CFRDocumentCallback() : startTime( 0 ) {}
    // 实现 IUnknown 方法
    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* document, 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;
};
 
// 调用 FlushTimer 方法以重置 startTime
void CFRDocumentCallback::FlushTimer() {
    time( &startTime );
}
 
// 此回调可能用于其他方法,
// 若不再需要超时功能,请将 shouldTrackTime 设置为 FALSE
void CFRDocumentCallback::SetShouldTrackTime( bool _shouldTrackTime ) {
    shouldTrackTime = _shouldTrackTime;
}
 
// 若当前时间与 "startTime" 之差超过某一阈值,
// 处理过程将被中止
HRESULT STDMETHODCALLTYPE CFRDocumentCallback::OnProgress( IFRDocument* frDocument, 
    int percentage, VARIANT_BOOL* shouldTerminate )
{
    if( shouldTrackTime ) {
        time_t currentTime;
        time( &currentTime );
        double seconds = difftime( currentTime, startTime );
        printf( "%f\n", seconds );
        *shouldTerminate = ( seconds > 100 ? VARIANT_TRUE : VARIANT_FALSE );
    }
    return S_OK;
}
此对象用于以下代码示例:EventsHandling (Windows 和 Linux) 。

备注

在 Linux 中,如果将 Engine 对象作为进程外服务器加载,则此接口将不起作用。

另请参见

FRDocument 使用可连接对象