Skip to main content
Visual Components are implemented in FRE for Windows.
When creating an application with a user interface, you can use ABBYY FineReader Engine Visual Components. Visual Components provide ready-to-use blocks for constructing your own user interface for an OCR application. You can show processing documents to the user of your application, allow the user to verify recognition results, and edit recognized text. Visual Components can be useful in all processing scenarios. For example, text editing can be provided in the Document Conversion scenario, while verification is extremely useful in Field-Level Recognition scenario. Let’s look at the simple OCR application from the user interface point of view. A document goes through several processing steps:
  1. Image opening
You can show the opened image to the user and allow the user to navigate between pages of the processing document.
  1. Recognition
To extract text data from a document, the document needs to be recognized. You can show recognized text to the user and allow him to edit the text.
  1. Verification
The recognized text may need to be verified. You can show both the source image and the recognized text to the user in order that they can be compared.
  1. Export
The recognized document can be saved to a suitable storage format or opened in an external application. Below follows a detailed description of the way to use ABBYY FineReader Engine Visual Components.
The Visual Components require Microsoft Windows Common Controls of version 6.0 or later.
Visual Studio enables you to insert ActiveX controls into your dialog box. You can add Visual Components to the Toolbox window (the Toolbox is available from the View menu) and work with them:
  1. On the Tools menu, click Choose Toolbox Items (or Add/Remove Toolbox Items).
  2. In the dialog box that opens, click the COM Components tab and select the ABBYY DocumentViewer, ABBYY ImageViewer, ABBYY ZoomViewer, ABBYY TextEditor, and ABBYY TextValidator components.
  3. Click OK. Icons for the selected items are now available in the Toolbox. You can drag and drop each Visual Component icon onto a design view surface. This action also adds the fundamental code to create an instance of the Visual Component in the active project file.
  4. After you have added the Visual Component to a form, you can specify its properties available in Visual Studio. For example, the SettingsPath property of each component should be specified at design time.
The Visual Studio designer does not support 64-bit ActiveX controls. Due to this fact, you cannot add 64-bit Visual Components to a Windows Form application. This is a known behavior; similar issues are described for Microsoft ActiveX controls, e.g., in http://support.microsoft.com/kb/980533/en-us. To provide a workaround for this issue, FineReader Engine installs both 32-bit and 64-bit Visual Components if you select Visual Components for developer installation on a 64-bit system. In this case, in Visual Studio designer, you can work with the 32-bit version of components. A 64-bit application that uses Visual Components does not need 32-bit Visual Components installed.
The Component Synchronizer component allows you to synchronize Visual Components in the application. That means that all viewing and editing operations will be processed synchronously in all connected components. To synchronize Visual Components:
  1. On form loading, create a new ComponentSynchronizer object.
  2. Use the DocumentViewer, ImageViewer, ZoomViewer, TextEditor, TextValidator properties of the ComponentSynchronizer object to connect the components to the synchronizer.
When a component is connected to the synchronizer through the API, Component Synchronizer works as described in How Component Synchronizer Works.

C#

private void VisualComponentsForm_Load(object sender, System.EventArgs e)
{
 // Attach components to Synchronizer
 Synchronizer = new FineReaderVisualComponents.ComponentSynchronizerClass();
 Synchronizer.DocumentViewer = ( FineReaderVisualComponents.DocumentViewer ) documentViewer.GetOcx();
 Synchronizer.ImageViewer = ( FineReaderVisualComponents.ImageViewer ) imageViewer.GetOcx();
 Synchronizer.ZoomViewer = ( FineReaderVisualComponents.ZoomViewer ) zoomViewer.GetOcx();
 Synchronizer.TextEditor = ( FineReaderVisualComponents.TextEditor ) textEditor.GetOcx();
}
To start working with ABBYY FineReader Engine, you need to create the Engine object. To create the Engine object, you can use the InitializeEngine exported function. See also other ways to load Engine object. You may load the Engine object during image loading or form initialization.

C#

[DllImport( "FREngine.dll", CharSet=CharSet.Unicode ), PreserveSig]
private static extern int InitializeEngine(
 String customerProjectID,
 String licensePath,
 String licensePassword,
 String FREngineDataFolder,
 String FREngineTempFolder,
 Bool lsSharedCPUCoresMode,
 ref FREngine.IEngine engine );
private void loadEngine()
{
 int hresult = InitializeEngine( "<CustomerProjectID>",
 "<licensePath>",
 "<licensePassword>",
 "<FREngineDataFolder>",
 "<FREngineTempFolder>",
 false,
 ref Engine );
 Marshal.ThrowExceptionForHR( hresult );
}
To display the image in the Visual Components, you should open it. You may implement the following procedure for image opening:
  1. To load images of a single document, you should create the FRDocument object and add images to it. You may do one of the following:
  2. Attach the document to Component Synchronizer using the Document property of the ComponentSynchronizer object.
The procedure can handle the “on click” event for a button that opens images.

C#

private void openImage( string imageFileName )
{
 // Load ABBYY FineReader Engine
 if( Engine == null )
 {
  loadEngine();
  Engine.ParentWindow = this.Handle.ToInt32();
  Engine.ApplicationTitle = this.Text;
 }
 // Open image
 Document = Engine.CreateFRDocumentFromImage( imageFileName, null );
 // Attach image to Visual Components using Synchronizer
 Synchronizer.Document = Document;
}
Recognition of an image in Visual Components can be called either using the commands, available in components or using FineReader Engine API (see, for example, the Process method of the FRDocument object).You may implement the following procedure for recognition:
  1. Recognize the document using the methods of the FRDocument object.
  2. The document has been changed not through Visual Components GUI, therefore you need to report the changes to Visual Components. Use the Update method of the FRPage object for each page in the document.
The procedure can handle the “on click” event for a button that calls recognition.

C#

private void recognizeDocument()
{
 // Recognize and synthesize the whole document
 Document.Process( Synchronizer.ProcessingParams );
 // Report the changes to Visual Components
 for( int i = 0; i < Document.Pages.Count; i++ )
 {
  Document.Pages[i].Update();
 }
}
The recognized data can be verified using the Text Validator component. It provides the user interface which allows you to check whether a character has been recognized correctly and correct it if necessary.You may implement the following procedure for verification:
  1. Add the Text Validator component to the current form or create a new form for it.
  2. Attach the Text Validator component to Component Synchronizer. Use the TextValidator property of the ComponentSynchronizer object.
  3. Start the verification process using the Spell method of the TextValidator object.

C#

private void validateButton_Click(object sender, System.EventArgs e)
{
 if( validatorForm == null )
 {
  // Create new form for validation
  validatorForm = new ValidatorForm();
  validatorForm.Owner = this;
  // Attach validator to synchronizer
  Synchronizer.TextValidator = ( FineReaderVisualComponents.TextValidator ) validatorForm.TextValidator.GetOcx();
  validatorForm.Show();
  // Validate the recognized text in the attached document
  validatorForm.TextValidator.Spell( null );
 }
}
The recognized document can be saved either by using commands available in the Document Viewer, or using FineReader Engine API.For example, use the Export method of the FRDocument object by assigning the FileExportFormatEnum constant as one of the parameters. After you have finished your work with the FRDocument object, release all the resources that were used by this object. Use the IFRDocument::Close method. The procedure can handle the “on click” event for a button that calls export.

C#

// Save a recognized document to RTF
Document.Export( "<File name>", FREngine.FileExportFormatEnum.FEF_RTF, null );
// Release the FRDocument object
Document.Close();
After finishing your work with ABBYY FineReader Engine, you need to unload the Engine object. To do this, use the DeinitializeEngine exported function.
We recommend that you release Component Synchronizer before Engine deinitialization.
The procedure can handle the “on click” event for a button that closes the application window.

C#

[DllImport( "FREngine.dll", CharSet=CharSet.Unicode ), PreserveSig]
private static extern int DeinitializeEngine();
private void unloadEngine()
{
 if( Engine != null )
 {// If Engine was loaded, unload it
  Engine = null;
  int hresult = DeinitializeEngine();
  Marshal.ThrowExceptionForHR( hresult );
 }
}
You can find a sample implementation of the described procedure in the VisualComponents sample.

See also

Customizing the Context Menu and Toolbar of a Visual Component