Skip to content

Document Processing

When the initialization is completed successfully, you can start the document processing. To start the document processing, a scenario must be set. In the examples below, we will use the Full Processing scenario.

There are two ways to process documents:

Using Built-in Camera

1. For iOS devices, add permissions:

Add the NSCameraUsageDescription permission to your Info.plist - this is needed to grant access to the device's camera:

Info.plist
<key>NSCameraUsageDescription</key>
<string>Is used to access to the camera</string>

2. Set the processing scenario:

let config = DocReader.ScannerConfig()
config.scenario = RGL_SCENARIO_FULL_PROCESS
RGLScannerConfig *config = [[RGLScannerConfig alloc] init];
config.scenario = RGL_SCENARIO_FULL_PROCESS;
val scannerConfig = ScannerConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).build()
ScannerConfig scannerConfig = new ScannerConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).build();
var config = ScannerConfig.withScenario(Scenario.FULL_PROCESS);
var config = ScannerConfig.withScenario(Scenario.FULL_PROCESS)
// Android
ScannerConfig config = new ScannerConfig.Builder(Scenario.ScenarioFullProcess).Build();

// iOS
RGLScannerConfig config = new()
{
    Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
};
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS

3. After the processing scenario is set, start the recognition process.

The Camera Frame interface for document capturing is available in both current (SDK versions 8.1+) and deprecated (before 8.1) design.

DocReader.shared.startScanner(presenter: self, config: config) { (action, result, error) in
    if action == .complete || action == .processTimeout {
        print(result)
    }
}
[RGLDocReader.shared startScannerFromPresenter:self config:config completion:^(enum RGLDocReaderAction action, RGLDocumentReaderResults * _Nullable results, NSError * _Nullable error) {
    if (action == RGLDocReaderActionComplete || action == RGLDocReaderActionProcessTimeout) {
        NSLog(@"%@", results);
    }
}];
DocumentReader.Instance().startScanner(this@MainActivity, scannerConfig, completion)

private val completion = IDocumentReaderCompletion { action, results, error ->
    if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT ) { 
        // document processing was finished
    }
}
DocumentReader.Instance().startScanner(MainActivity.this, scannerConfig, completion);

private IDocumentReaderCompletion completion = new IDocumentReaderCompletion() {
    @Override
    public void onCompleted(int action, DocumentReaderResults results, Throwable error) {
        if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT ) { 
            // document processing was finished
        }
    }
};
DocumentReader.instance.startScanner(config, (action, results, error) {
  if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT) {
    // document processing was finished
  }
});
DocumentReader.instance.startScanner(config, (action, results, error) => {
  if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT) {
    // document processing was finished
  }
})
eventManager.addListener('completion', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))

DocumentReader.startScanner(config, _ => { }, _ => { })

handleCompletion(completion) {
    // handle results
}
DocumentReader.startScanner(config).subscribe(m => {
    // handle results
})
DocumentReader.startScanner(config, function(m) {
    // handle results
}, function(e) { })
// Android
public void Start()
{
    ScannerConfig config = new ScannerConfig.Builder(Scenario.ScenarioFullProcess).Build();
    DocumentReader.Instance().StartScanner(Platform.AppContext, config, this);
}

public void OnCompleted(int action, DocumentReaderResults results, string error)
{
    // handle completion
}

// iOS
public partial class ViewController : UIViewController
{
    partial void Start()
    {
        RGLScannerConfig config = new()
        {
            Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
        };
        RGLDocReader.Shared.StartScannerFromPresenter(CurrentPresenter, config, StartScannerCompleted);
    }

    void StartScannerCompleted(RGLDocReaderAction action, RGLDocumentReaderResults result, string error)
    {
        // handle completion
    }
}
DocReader.shared.showScanner(presenter: self, config: config) { (action, result, error) in
    if action == .complete || action == .processTimeout {
        print(result)
    }
}
[RGLDocReader.shared showScannerFromPresenter:self config:config completion:^(enum RGLDocReaderAction action, RGLDocumentReaderResults * _Nullable results, NSError * _Nullable error) {
    if (action == RGLDocReaderActionComplete || action == RGLDocReaderActionProcessTimeout) {
        NSLog(@"%@", results);
    }
}];
DocumentReader.Instance().showScanner(this@MainActivity, scannerConfig, completion)

private val completion = IDocumentReaderCompletion { action, results, error ->
    if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT ) { 
        // document processing was finished
    }
}
DocumentReader.Instance().showScanner(MainActivity.this, scannerConfig, completion);

private IDocumentReaderCompletion completion = new IDocumentReaderCompletion() {
    @Override
    public void onCompleted(int action, DocumentReaderResults results, Throwable error) {
        if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT ) { 
            // document processing was finished
        }
    }
};
DocumentReader.instance.scan(config, (action, results, error) {
  if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT) {
    // document processing was finished
  }
});
DocumentReader.instance.scan(config, (action, results, error) => {
  if (action == DocReaderAction.COMPLETE || action == DocReaderAction.TIMEOUT) {
    // document processing was finished
  }
})
eventManager.addListener('completion', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))

DocumentReader.scan(config, _ => { }, _ => { })

handleCompletion(completion) {
    // handle results
}
DocumentReader.scan(config).subscribe(m => {
    // handle results
})
DocumentReader.scan(config, function(m) {
    // handle results
}, function(e) { })
// Android
public void Start()
{
    ScannerConfig config = new ScannerConfig.Builder(Scenario.ScenarioFullProcess).Build();
    DocumentReader.Instance().ShowScanner(Platform.AppContext, config, this);
}

public void OnCompleted(int action, DocumentReaderResults results, string error)
{
    // handle completion
}

// iOS
public partial class ViewController : UIViewController
{
    partial void Start()
    {
        RGLScannerConfig config = new()
        {
            Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
        };
        RGLDocReader.Shared.ShowScannerFromPresenter(CurrentPresenter, config, ShowScannerCompleted);
    }

    void ShowScannerCompleted(RGLDocReaderAction action, RGLDocumentReaderResults result, string error)
    {
        // handle completion
    }
}

During the processing, actions that demonstrate the state of the camera are received. For example, COMPLETE means that the processing is completed and the processing results can be handled. You can find all available actions and their descriptions in our API Reference documentation:

1. Add permissions:

Add the NSPhotoLibraryUsageDescription permission to your Info.plist - this is needed to grant access to the device's gallery:

Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>Is used to access to the gallery</string>

Add the READ_EXTERNAL_STORAGE permission to your AndroidManifest - this is needed to grant access the device's gallery:

AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

2. Set the processing scenario:

let config = DocReader.RecognizeConfig(images: images)
config.scenario = RGL_SCENARIO_FULL_PROCESS
RGLRecognizeConfig *config = [[RGLRecognizeConfig alloc] initWithImages:images];
config.scenario = RGL_SCENARIO_FULL_PROCESS;
val recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setBitmaps(bitmaps).build()
RecognizeConfig recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setBitmaps(bitmaps).build();
var config = RecognizeConfig.withScenario(
  Scenario.FULL_PROCESS,
  images: await getImages()
);
var config = RecognizeConfig.withScenario(Scenario.FULL_PROCESS, { images })
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
// Android
RecognizeConfig config = new RecognizeConfig.Builder(Scenario.ScenarioFullProcess).SetBitmap(bitmap).Build();

// iOS
RGLRecognizeConfig config = new(image)
{
    Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
};

3. Start the recognition process:

  • To process one or more images as bitmaps, use:
let config = DocReader.RecognizeConfig(images: images)
config.scenario = RGL_SCENARIO_FULL_PROCESS

DocReader.shared.recognize(config: config) { (action, result, error) in
    if action == .complete {
        print(result)
    }
}
RGLRecognizeConfig *config = [[RGLRecognizeConfig alloc] initWithImages:images];
config.scenario = RGL_SCENARIO_FULL_PROCESS;

[RGLDocReader.shared recognizeWithConfig:config completion:^(RGLDocReaderAction action, RGLDocumentReaderResults * _Nullable results, NSError * _Nullable error) {
    if (action == RGLDocReaderActionComplete || action == RGLDocReaderActionProcessTimeout) {
        NSLog(@"%@", results);
    }
}];
val recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setBitmaps(bitmaps).build()
DocumentReader.Instance().recognize(recognizeConfig, completion)
RecognizeConfig recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setBitmaps(bitmaps).build();
DocumentReader.Instance().recognize(recognizeConfig, completion);
var config = RecognizeConfig.withScenario(
  Scenario.FULL_PROCESS,
  images: await getImages()
);
DocumentReader.instance.recognize(config, completion);
var config = RecognizeConfig.withScenario(Scenario.FULL_PROCESS, { images })
DocumentReader.instance.recognize(config, completion)
eventManager.addListener('completion', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))

var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
DocumentReader.recognize(config, _ => { }, _ => { })

handleCompletion(completion) {
    // handle results
}
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
DocumentReader.recognize(config).subscribe(m => {
    // handle results
})
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.images = images
DocumentReader.recognize(config, function(m) {
    // handle results
}, function(e) { })
// Android
public void Recognize()
{
    RecognizeConfig config = new RecognizeConfig.Builder(Scenario.ScenarioFullProcess).SetBitmap(bitmap).Build();
    DocumentReader.Instance().Recognize(Platform.AppContext, config, this);
}

public void OnCompleted(int action, DocumentReaderResults results, string error)
{
    // handle completion
}

// iOS
public partial class ViewController : UIViewController
{
    partial void Recognize()
    {
        RGLRecognizeConfig config = new(image)
        {
            Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
        };
        RGLDocReader.Shared.RecognizeWithConfig(config, HandleRGLDocumentReaderCompletion);
    }

    void HandleRGLDocumentReaderCompletion(RGLDocReaderAction action, RGLDocumentReaderResults result, NSError error)
    {
        // handle completion
    }
}
  • To process one or more images as binary array, use:
let config = DocReader.RecognizeConfig(scenario: RGL_SCENARIO_FULL_PROCESS)

// set array of images as binary arrays
config.imageDataArray = dataArray

// or set single image as binary array
// config.imageData = data 

DocReader.shared.recognize(config: config) { (action, result, error) in
    if action == .complete {
        print(result)
    }
}
RGLRecognizeConfig *config = [[RGLRecognizeConfig alloc] initWithScenario:RGL_SCENARIO_FULL_PROCESS];

// set array of images as binary arrays
config.imageDataArray = dataArray; 

// or set single image as binary array
// config.imageData = data;

[RGLDocReader.shared recognizeWithConfig:config completion:^(RGLDocReaderAction action, RGLDocumentReaderResults * _Nullable results, NSError * _Nullable error) {
    if (action == RGLDocReaderActionComplete || action == RGLDocReaderActionProcessTimeout) {
        NSLog(@"%@", results);
    }
}];
val recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setData(data).build()
DocumentReader.Instance().recognize(recognizeConfig, completion)
RecognizeConfig recognizeConfig = RecognizeConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).setData(data).build();
DocumentReader.Instance().recognize(recognizeConfig, completion);
var config = RecognizeConfig.withScenario(Scenario.FULL_PROCESS);

// set array of images as binary arrays
config.dataList = dataList;

// or set single image as binary array
// config.data = data;

DocumentReader.instance.recognize(config, completion);
var config = RecognizeConfig.withScenario(Scenario.FULL_PROCESS);

// set array of images as binary arrays
config.dataList = dataList;

// or set single image as binary array
// config.data = data;

DocumentReader.instance.recognize(config, completion);
eventManager.addListener('completion', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))

var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.data = data
DocumentReader.recognize(config, _ => { }, _ => { })

handleCompletion(completion) {
    // handle results
}
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.data = data
DocumentReader.recognize(config).subscribe(m => {
    // handle results
})
var config = new RecognizeConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
config.data = data
DocumentReader.recognize(config, function(m) {
    // handle results
}, function(e) { })
// Android
public void Recognize()
{
    var config = new RecognizeConfig.Builder(Scenario.ScenarioFullProcess);

    // set array of images as binary arrays
    config.SetData(dataList); 

    // or set single image as binary array
    // config.SetData(data);

    DocumentReader.Instance().Recognize(Platform.AppContext, config.Build(), this);
}

public void OnCompleted(int action, DocumentReaderResults results, string error)
{
    // handle completion
}

// iOS
public partial class ViewController : UIViewController
{
    partial void Recognize()
    {
        // set array of images as binary arrays
        RGLRecognizeConfig config = new(dataArray) { Scenario = Constants.RGL_SCENARIO_FULL_PROCESS };

        // or set single image as binary array
        // RGLRecognizeConfig config = new(data) { Scenario = Constants.RGL_SCENARIO_FULL_PROCESS };

        RGLDocReader.Shared.RecognizeWithConfig(config, HandleRGLDocumentReaderCompletion);
    }

    void HandleRGLDocumentReaderCompletion(RGLDocReaderAction action, RGLDocumentReaderResults result, NSError error)
    {
        // handle completion
    }
}

In the examples above, data / dataArray is a byte array (or array of byte arrays) containing image data in .pdf, .jpg, .png, or another supported file format.

You can find other methods used for frames processing in the API Reference documentation:

Next Steps