Using ABBYY FlexiCapture SDK in Java

Because Java is platform-independent, it has no special tools for integration with platform-dependent technologies such as COM. Instead, it provides a truly platform-independent but very low-level interface for integration with any native platform – Java Native Interface (JNI). Creating wrappers using JNI is not an easy task: you should write huge amount of code to implement wrappers for all necessary interfaces and methods. But there is no need to do it for FlexiCapture SDK. FlexiCapture SDK provides ready-to-use Java classes for the Engine library. These Java classes can be used directly from Java applications.

Adding FlexiCapture SDK library to a Java project

ABBYY FlexiCapture SDK includes the com.abbyy.FCEngine.jar file, which contains the Java class library for FlexiCapture SDK. You can find it in the Inc\Java folder. The path to this file can be specified in classpath parameter in the command line and in projects settings in different Java development environments. For example:

%JDK%\bin\Javac -classpath <path>/com.abbyy.FCEngine.jar

%JDK% is the path to Java Development Kit.

Note: See the supported Java Development Kit version in System Requirements.

Loading and unloading FlexiCapture SDK

To load the Engine object, you can use the static Engine class:

  1. Use its Load method to load FlexiCapture SDK, and Unload method – to unload it. This way is identical to the standard way of loading and unloading the Engine object.
  2. Use its CreateEngineInprocLoader or CreateEngineOutprocLoader methods to load Engine by means of COM. See the description of the IEngineLoader interface for details. If you use the CreateEngineOutprocLoader method for loading, you do not need to call IWorkProcessControl::SetParentProcessId method, because it is done automatically.

The following code sample illustrates the use of FlexiCapture SDK in Java.

import com.abbyy.FCEngine.*;
public class Hello {
 public static void main( String[] args )
    try {
         // Load the Engine
         IEngineLoader engineLoader = Engine.GetEngineLoader( SamplesConfig.GetDllPath() );
         engineLoader.setCustomerProjectId( SamplesConfig.GetCustomerProjectId() );
         engineLoader.setLicensePath( SamplesConfig.GetLicensePath() );
         engineLoader.setLicensePassword( SamplesConfig.GetLicensePassword() );
         IEngine engine = engineLoader.GetEngine();
            // Open a project and work with it
            IProject project = engine.OpenProject( "D:\\TestProject\\Testproject.fcproj" );
         } catch {
         } finally {
     } catch( Exception ex ) {
         trace( ex.getMessage() );

For working with the Engine object created via an engine loader, the Engine class provides the methods which call the corresponding COM functions to marshal the interface pointer across threads:

Method Signature Comment
long MarshalInterface();

Calls the CoMarshalInterface COM function to marshal the IEngine interface. This method should be called on the thread where the engine was created, to ensure that the data needed for creating a proxy object on another thread will be available.

Returns the handle to the marshaling data.

IEngine UnmarshalInterface( long handle );

Calls the CoUnmarshalInterface COM function to unmarshal the IEngine interface, i.e. create a proxy object with which the client process will be able to interact in the same way as with the engine itself.

Takes the handle to the marshaling data (returned by the MarshalInterface method) as the input parameter and returns a pointer to the IEngine interface.

ABBYY FlexiCapture SDK includes a simple Hello sample in Java. You can access this sample by selecting Start > Programs > ABBYY FlexiCapture 12 SDK > Code Samples Folder > Hello (Java).

Calling methods with out-parameters

There are several methods in ABBYY FlexiCapture SDK which have out-parameters that receive a new value after the method call and must be passed by reference. These parameters are marked in the type library and in descriptions of methods in this Developer's Help as [out] or [in, out].

When working with ABBYY FlexiCapture SDK in Java, you have to use a special Ref class to pass a parameter by reference. See examples below.

Example in which the out-parameters are passed by reference to the IReadStream::Read method:

Sample code for out-parameters

15.08.2023 13:19:30

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.