To add our SDK to your own application, you should add it to the build process of your application. Currently we only support doing this using Gradle.
Adding the SDK to your gradle build file consist of two steps:
To add the repository to your project, open the settings.gradle file in your application.
Edit the repositories part of your settings.gradle, so that it contains the following:
maven {
credentials {
username 'ExampleUsername'
password 'ExamplePassword'
}
url "https://custom-ocr.klippa.com/sdk/android/maven"
}
maven { url "https://jitpack.io" }
We add jitpack.io because some of our dependencies are hosted there. If your settings.gradle already contains jitpack.io, don't add it.
The full repositories section of your settings.gradle might look like this now:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
maven {
credentials {
username 'ExampleUsername'
password 'ExamplePassword'
}
url "https://custom-ocr.klippa.com/sdk/android/maven"
}
maven { url "https://jitpack.io" }
}
}
Edit the dependencies part of your build.gradle, so that it contains the following:
implementation 'com.klippa:ocrapi:0.1.1'
The full dependencies section of your build.gradle might look like this now:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.klippa:ocrapi:0.1.1'
}
When you build your app now, it should download our library as dependency, and with that all dependencies of our library.
Currently the OCR API supports parsing of around 30 templates.
To use the OCR API, generate a Public API key with our API through your own backend, this makes sure your API key won't be leaked and/or abused.
Using the SDK, import our package:
// Add to the top of your file
import com.klippa.ocrapi.api.ParsingApi
import com.klippa.ocrapi.infrastructure.ApiClient
To parse a document (Receipt) with the OCR Api use the following call:
Executors.newSingleThreadExecutor().execute {
try {
val result = parsingAPI.parseDocumentFinancialFull(
document = image.file
)
val totalAmount = result.data?.parsed?.amount ?: return@execute
} catch (e: Exception) {
Log.e("TAG", e.toString())
}
}
Or call the following for a identity document:
Executors.newSingleThreadExecutor().execute {
try {
val result = parsingAPI.parseDocumentIdentityDocument(
document = image.file
)
val documentType = result.data?.documentType
} catch (e: Exception) {
Log.e("TAG", e.toString())
}
}
The following versions are available:
| Version | Gradle dependency | JavaDoc |
|---|---|---|
| 0.1.1 | implementation 'com.klippa:ocrapi:0.1.1' | Download |
| 0.1.0 | implementation 'com.klippa:ocrapi:0.1.0' | Download |
| 0.0.5 | implementation 'com.klippa:ocrapi:0.0.5' | Download |
| 0.0.4 | implementation 'com.klippa:ocrapi:0.0.4' | Download |