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:
<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()
DocumentReader.Instance().showScanner(this@MainActivity, scannerConfig, completion)
ScannerConfig scannerConfig = new ScannerConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).build();
DocumentReader.Instance().showScanner(MainActivity.this, scannerConfig, completion);
var config = ScannerConfig.withScenario(Scenario.FULL_PROCESS);
DocumentReader.instance.scan(config, completion);
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
DocumentReader.scan(config, _ => { }, _ => { })
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
DocumentReader.scan(config)
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
DocumentReader.scan(config, function (m) { }, function (e) { });
// Android
ScannerConfig config = new ScannerConfig.Builder(Scenario.ScenarioFullProcess).Build();
DocumentReader.Instance().ShowScanner(Platform.AppContext, config, this);
// iOS
RGLScannerConfig config = new()
{
Scenario = Constants.RGL_SCENARIO_FULL_PROCESS
};
RGLDocReader.Shared.ShowScannerFromPresenter(CurrentPresenter, config, OnResultsObtained);
3. Start the recognition process:
let config = DocReader.ScannerConfig()
config.scenario = RGL_SCENARIO_FULL_PROCESS
DocReader.shared.showScanner(presenter: self, config: config) { (action, result, error) in
if action == .complete || action == .processTimeout {
print(result)
}
}
RGLScannerConfig *config = [[RGLScannerConfig alloc] init];
config.scenario = RGL_SCENARIO_FULL_PROCESS;
[RGLDocReader.shared showScannerFromPresenter:self config:config completion:^(enum RGLDocReaderAction action, RGLDocumentReaderResults * _Nullable results, NSError * _Nullable error) {
if (action == RGLDocReaderActionComplete || action == RGLDocReaderActionProcessTimeout) {
NSLog(@"%@", results);
}
}];
val scannerConfig = ScannerConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).build()
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
}
}
ScannerConfig scannerConfig = new ScannerConfig.Builder(Scenario.SCENARIO_FULL_PROCESS).build();
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
}
}
};
var config = ScannerConfig.withScenario(Scenario.FULL_PROCESS);
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"]))))
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
DocumentReader.scan(config, _ => { }, _ => { })
handleCompletion(completion) {
// handle results
}
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
DocumentReader.scan(config).subscribe(m => {
// handle results
})
var config = new ScannerConfig()
config.scenario = ScenarioIdentifier.SCENARIO_FULL_PROCESS
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:
Picking Images from Gallery
1. Add permissions:
Add the NSPhotoLibraryUsageDescription
permission to your Info.plist - this is needed to grant access to the device's gallery:
<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:
<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 = 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, 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);
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 image as binary, use:
let config = DocReader.RecognizeConfig(imageData: data)
config.scenario = RGL_SCENARIO_FULL_PROCESS
DocReader.shared.recognize(config: config) { (action, result, error) in
if action == .complete {
print(result)
}
}
RGLRecognizeConfig *config = [[RGLRecognizeConfig alloc] initWithImageData:data];
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).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,
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()
{
RecognizeConfig config = new RecognizeConfig.Builder(Scenario.ScenarioFullProcess).SetData(data).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(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
is an image in .pdf
, .jpg
, .png
, or other format.
You can find other methods used for frames processing in the API Reference documentation: