# 2. FOCR SDK Features

## Init gateway

Contact us for get `app_id` & `secret_key`

{% tabs %}
{% tab title="Java" %}

```java
OCRManager.initGateway(appId, secretKey, new IInitGatewayCallback() {
  @Override
  public void onSuccess() {

  }

  @Override
  public void onFail(@Nullable AppException error) {

  }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```java
OCRManager.initGateway(appId, secretKey, object : IInitGatewayCallback {
  override fun onSuccess() {

  }

  override fun onFail(error: AppException?) {

  }
})
```

{% endtab %}
{% endtabs %}

## Register OCR callback

**After registration, the SDK will return the corresponding status in the callback**

<table><thead><tr><th width="241">Status</th><th>Description</th></tr></thead><tbody><tr><td>onStart</td><td>Called at start OCR</td></tr><tr><td>onSuccess</td><td>Called when return result</td></tr><tr><td>onFail</td><td>Called when an error occurs in process</td></tr></tbody></table>

{% tabs %}
{% tab title="Java" %}

```java
OCRManager.registerOCRCallback(new IOCRCallback() {
  @Override
  public void onStart() {

  }

  @Override
  public void onFail(@Nullable AppException error) {

  }

  @Override
  public void onSuccess(@NonNull OCRData result) {

  }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
OCRManager.registerOCRCallback(object : IOCRCallback {
  override fun onStart() {

  }


  override fun onFail(error: AppException?) {

  }

  override fun onSuccess(result: OCRData) {

  })
})
```

{% endtab %}
{% endtabs %}

## Get Config

* Get list config used to ocr param
* When sucess, result is `listConfig`, it will be called on `onSuccess()` in callback
* When fail, it will called on `onFail()` in callback

{% tabs %}
{% tab title="Java" %}

```java
OCRManager.getConfig(new IOCRConfigCallback() {
    @Override
    public void onSuccess(@NonNull List<OCRConfigData> listConfig) {
        
    }

    @Override
    public void onFail(@Nullable AppException error) {

    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
OCRManager.getConfig(object : IOCRConfigCallback {
    override fun onSuccess(listConfig: List<OCRConfigData>) {

    }

    override fun onFail(error: AppException?) {
    
    }
})
```

{% endtab %}
{% endtabs %}

## Start OCR

* Used to start OCR
* When successful start, it will be called on `onStart()` in callback
* When have result `result` will be return on `onSuccess` in callback.
* When fails, it will be processed at callback `onFail()` in callback.

{% tabs %}
{% tab title="Java" %}

```java
//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file); 
...
//use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath); 
```

{% endtab %}

{% tab title="Kotlin" %}

```java
//use file
OCRManager.startOCR(documentType, responseFormat, toMathMl, file) 
...
 //use file path
OCRManager.startOCR(documentType, responseFormat, toMathMl, absoluteFilePath)
```

{% endtab %}
{% endtabs %}

## Export OCR data

* Used to export data OCR to csv or excel file
* `exportType` is `OCRExportType.CSV` or `OCRExportType.EXCEL`
* When export success `data` will be return on `onSuccess` in callback.
* When fails, it will be processed at callback `onFail()` in callback

{% tabs %}
{% tab title="Java" %}

```java
OCRManager.export(requestId, exportType, new IExportCallback() {
    @Override
    public void onSuccess(@NonNull String data) {
        
    }

    @Override
    public void onFail(@Nullable AppException error) {

    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
OCRManager.export(requestId, exportType, object : IExportCallback {
    override fun onSuccess(data: String) {

    }

    override fun onFail(error: AppException?) {
    
    }
})
```

{% endtab %}
{% endtabs %}

## UI Preview OCR data

```xml
<ai.ftech.focrsdk.sdk.FOCRView
    android:id="@+id/ocrView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
```

Then set OCRData from onSuccess to view&#x20;

```java
  ocrView.setData(ocrData)
```
