Skip to content

Initialization

To start the initialization process, you need to get the license file first. A demo license can be obtained at our Client Portal.

The initializeReader method is designed to perform the initialization process that accepts an instance of the configuration object. It allows you to set the license and other configuration properties.

For more information, have a look at the API Reference:

The example below shows how to perform initialization with the license stored in the application bundle. Note that in the next example the new configuration object is created, however, if you already have one (for example, populated with the custom database path), use that existing config for setting the license data and initializing DocReader.

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);
    }
}];
//Reading the license from raw resource file
val licInput = resources.openRawResource(R.raw.regula)
val available = licInput.available()
val license = ByteArray(available)

licInput.read(license)

DocumentReader.Instance().initializeReader(
    this@MainActivity, DocReaderConfig(license)
    ) { success, error_initializeReader ->
        if (success) {
            // initialization successful
        } else {
            // initialization was not successful
        }
}
//Reading the license from raw resource file
InputStream licInput = getResources().openRawResource(R.raw.regula);
int available = licInput.available();
byte[] license = new byte[available];
//noinspection ResultOfMethodCallIgnored
licInput.read(license);

DocumentReader.Instance().initializeReader(MainActivity.this, new DocReaderConfig(license), new IDocumentReaderInitCompletion() {
    @Override
    public void onInitCompleted(boolean success, Throwable error) {
        if (success) {
            // initialization successful
        } else {
            // initialization was not successful
        }
    }
});
var initConfig = InitConfig(await rootBundle.load("assets/regula.license"));
var (success, error) = await documentReader.initializeReader(initConfig);
if (success) {
  // initialization successful
} else {
  print(error!.message); // initialization was not successful
}
DocumentReader.initializeReader({
    license: data
}, (respond) => {
    // do something
}, error => console.log(error));
DocumentReader.initializeReader({
    license: license
}).then(m => console.log("Initialized")).catch(error)
DocumentReader.initializeReader({
    license: license
}, function(message) {
    // set up the processing settings
}, function(error) {
    console.log(error)
})
// Android
public class MainActivity : DocumentReader.IDocumentReaderInitCompletion
{
    protected void initReader()
    {
        var bytes = default(byte[]);
        using (var streamReader = new StreamReader(Assets.Open("regula.license")))
        {
            using (var memstream = new MemoryStream())
            {
                streamReader.BaseStream.CopyTo(memstream);
                bytes = memstream.ToArray();
            }
        }

        DocumentReader.Instance().InitializeReader(this, new DocReaderConfig(bytes), this);
    }

    public void OnInitCompleted(bool success, string error)
    {
        // handle completion
    }
}

// iOS
var licenseData = NSData.FromFile(NSBundle.MainBundle.PathForResource("regula.license", null));

if (licenseData == null)
{
    return;
}

RGLDocReader.Shared.InitializeReader(licenseData, (bool successfull, NSError error) => {
    // handle completion
});

By default, the Document Reader SDK attempts to access the licensing server to keep your license updated. You can turn this option off:

Next Steps