Integrating Our OCR SDK into Android

This guide explains the process of integrating the OCR library of PSPDFKit for Android into your project. The OCR library is designed to work best with Android Studio and the Gradle build system. We recommend Android Studio as the IDE and Android Gradle plugin 8.2.0 or higher for development.

Setting Up OCR

Below is a list of steps required to set up OCR.

Step 1 — Adding PSPDFKit and OCR to Your Project

  1. In your top-level build.gradle file, add the PSPDFKit Maven repository:

    allprojects {
        repositories {
            maven {
                url 'https://my.pspdfkit.com/maven/'
            }
        }
    }
  2. In your app-level build.gradle file, add the PSPDFKit and OCR dependencies:

    dependencies {
        final pspdfkit_version = '2024.1.2'
        implementation "com.pspdfkit:pspdfkit:$pspdfkit_version"
        implementation "com.pspdfkit:pspdfkit-ocr:$pspdfkit_version"
    }

Step 2 — Adding OCR Language Packs

For each supported language you want to perform OCR for, your app needs to contain a language pack. Each language pack has to be added as a dependency, either to your primary application module, or transitively — for example, by adding it to a dynamic feature APK module, which can be downloaded to a device on demand using Play Feature Delivery.

To add one or more OCR language packs to an Android module, specify them inside the dependencies block of that module:

dependencies {
    // The language pack version has to match the PSPDFKit and OCR library versions.
    final pspdfkit_version = '2024.1.2'

    // Pick one or more language packs from this list.
    api "com.pspdfkit:pspdfkit-ocr-croatian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-czech:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-danish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-dutch:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-english:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-finnish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-french:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-german:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-indonesian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-italian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-malay:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-norwegian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-polish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-portuguese:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-serbian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-slovak:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-slovenian:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-spanish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-swedish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-turkish:$pspdfkit_version"
    api "com.pspdfkit:pspdfkit-ocr-welsh:$pspdfkit_version"
}

ℹ️ Note: When adding language packs transitively to submodules of your primary app module (for example, with Play Feature Delivery), make sure to specify the language packs using the api configuration instead of implementation.

Catalog Example

You can find a runnable OcrExample inside our Catalog app, and it showcases the use of OCR. To try out the OCR example in action, check out the Catalog Getting Started section.

Next Steps

Check out our OCR Usage guide to see how to use OCR inside your Android application with Java or Kotlin.