Simple scanner guide

Introduction

The scan flow consists of two screens that enable the user to capture and validate each page of its document:

  • a camera screen to scan the document
  • a screen where the user validates the scanned document and can optionally adjust the crop area, the filters.

If the multi-page mode is enabled, the user will repeat this interaction until they validate their batch of scan on the camera screen.

Camera screen
Review screen
Recrop screen

In this guide, you will learn how to integrate this simple scan flow with a couple of lines of code.

Prerequisites

This guide assumes that you have followed the Getting Started guide :

  • You have integrated the gssdk library in your app with Gradle.
  • You have initialized the SDK with the license key.

Start the scan flow

You configure the scan flow with a configuration object, which lets you configure features such as:

  • Source: capture from the camera or import an existing image from the device’s photo library
  • Camera flash mode: you can force the flash to be always on, or only enable it on demand.
  • Multi-page mode: can be enabled or disabled.
  • PDF page size and resolution.
  • Available actions in the post-processing screen.
  • Background and text colors of the different screens.

All these parameters are extensively documented in the Android API documentation.

Once the user finishes their scan session, the scan flow returns the scanned pages’ list as images and a PDF file combining all the pages.

Kotlin
val scanConfiguration = ScanConfiguration().apply {
  multiPage = true
}
ScanFlow.scanWithConfiguration(activity, scanConfiguration)
Java
ScanConfiguration scanConfiguration = new ScanConfiguration();
scanConfiguration.multiPage = true;
ScanFlow.scanWithConfiguration(activity, scanConfiguration);

and… that’s it!

Get the result of the scan flow

Implement the onActivityResult callback in the activity you used to start the scan flow and get a ScanResult using ScanFlow.getScanResultFromActivityResult. The result object will contain the PDF file as well as the images of the pages that were scanned.

Kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  try {
    val result = ScanFlow.getScanResultFromActivityResult(data)
    // Do anything with the images or the PDF file
  } catch (e: Exception) {
    // There was an error during the scan flow. Check the exception for more details.
  }
}
Java
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  try {
    ScanResult result = ScanFlow.getScanResultFromActivityResult(data);
    // Do anything with the images or the PDF file
  } catch (Exception e) {
    // There was an error during the scan flow. Check the exception for more details.
  }
}

An implicit API contract is that you have to take ownership of the resulting files referenced by the `ScanResult object. You are responsible for moving them to the appropriate place and deleting them if you don’t need them anymore.

© 2024 The Grizzly Labs. All rights reserved.