Skip to content

Initialization

How to perform the initialization of Document Reader SDK.

Overview

You can obtain a demo license here: https://client.regulaforensics.com

The initializeReaderWithConfig method initializes the Document Reader SDK. It accepts an instance of the RGLConfig class as a configuration object.

The RGLConfig allows you to set the license for the Document Reader SDK and other configuration properties. For more information, please see the documentation for RGLConfig.

The initialization of the Document Reader SDK is performed fully offline, although by default the SDK attempts to access the licensing server. You can change this behavior by setting the RGLConfig instance property licenseUpdateCheck to false.

Here is an example of how to perform initialization with the license stored in the application bundle:

guard let licensePath = Bundle.main.path(forResource: "regula.license", ofType: nil) else { return }
guard let licenseData = Data(contentsOf: URL(fileURLWithPath: licensePath)) else { return }
let config = DocReader.Config(license: licenseData)

DocReader.shared.initializeReader(config: config) { (success, error) in
    if success {
        // DocumentReader successfully initialized
    } else {
        // DocumentReader not initialized
        print(error)
    }
}
NSString *licensePath = [[NSBundle mainBundle] pathForResource:@"regula.license" ofType:nil];
NSData *licenseData = [NSData dataWithContentsOfFile:licensePath];
RGLConfig *config = [RGLConfig configWithLicenseData:licenseData];

[RGLDocReader.shared initializeReaderWithConfig:config completion:^(BOOL success, NSError *error) {
    if (success) {
        // DocumentReader successfully initialized
    } else {
        // DocumentReader not initialized
        NSLog(@"%@", error);
    }
}];

With Custom Database Path

Also, you can use a custom database path:

guard let licensePath = Bundle.main.path(forResource: "regula.license", ofType: nil) else { return }
guard let licenseData = Data(contentsOf: URL(fileURLWithPath: licensePath)) else { return }
let databasePath = Bundle.main.path(forResource: "db.dat", ofType: nil)
let config = DocReader.Config(license: licenseData, licenseUpdateCheck: true, databasePath: databasePath)

DocReader.shared.initializeReader(config: config) { (success, error) in
    if success {
        // DocumentReader successfully initialized
    } else {
        // DocumentReader not initialized
        print(error)
    }
}
NSString *licensePath = [[NSBundle mainBundle] pathForResource:@"regula.license" ofType:nil];
NSData *licenseData = [NSData dataWithContentsOfFile:licensePath];
NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"db.dat" ofType:nil];
RGLConfig *config = [RGLConfig configWithLicenseData:licenseData licenseUpdateCheck:YES databasePath:databasePath];

[RGLDocReader.shared initializeReaderWithConfig:config completion:^(BOOL success, NSError *error) {
    if (success) {
        // DocumentReader successfully initialized
    } else {
        // DocumentReader not initialized
        NSLog(@"%@", error);
    }
}];

Other Properties

/// DocumentReader configuration object.
/// Controls initialization time properties such as License and Database filepath.
class Config {
  /// The license binary file loaded as `Data`.
  var licenseData: Data { get set }

  /// Enables automatic license update check during `DocumentReader` initialization.
  /// Defaults to `true`.
  var licenseUpdateCheck: Bool { get set }

  /// The path to the database file.
  var databasePath: String? { get set }

  /// Defines whether the `DocumentReader` delays loading of neural networks. Defaults to `false`.
  ///
  /// When set to `true` the initialization starts in the background thread after a completion block passed to the method
  /// `-[RGLDocReader initializeReaderWithConfig:completion:]` is called. If the document processing is initiated before all the networks are loaded,
  /// the `DocuentReader` will wait for it before starting the handling.
  ///
  /// When set to `false` the initialization is performed during `DocumentReader` initialization `-[RGLDocReader initializeReaderWithConfig:completion:]` method.
  var isDelayedNNLoadEnabled: Bool { get set }
}
/// DocumentReader configuration object.
/// Controls initialization time properties such as License and Database filepath.
@interface RGLConfig : NSObject

/// The license binary file loaded as `Data`.
@property(readwrite, nonatomic, strong, nonnull) NSData *licenseData;

/// Enables automatic license update check during `DocumentReader` initialization.
/// Defaults to `true`.
@property(readwrite, nonatomic, assign) BOOL licenseUpdateCheck;

/// The path to the database file.
@property(readwrite, nonatomic, copy, nullable) NSString *databasePath;

/// Defines whether the `DocumentReader` delays loading of neural networks. Defaults to `false`.
///
/// When set to `true` the initialization starts in the background thread after a completion block passed to the method
/// `-[RGLDocReader initializeReaderWithConfig:completion:]` is called. If the document processing is initiated before all the networks are loaded,
/// the `DocuentReader` will wait for it before starting the handling.
///
/// When set to `false` the initialization is performed during `DocumentReader` initialization `-[RGLDocReader initializeReaderWithConfig:completion:]` method.
@property(readwrite, nonatomic, assign, getter=isDelayedNNLoadEnabled) BOOL delayedNNLoadEnabled;

@end