Skip to main content

Document Scan

The Docutain Document Scanner SDK for Kotlin Multiplatform comes with integrated, ready-to-use UI components for the document scan process. Colors and button titles can be changed to match your branding from shared code.

It is also possible to use the Document Scanner on imported images.

ScanEditPreview

Initialization​

  • Follow the Getting started guide
  • Initialize the Docutain SDK for Kotlin Multiplatform as described here

Scan with Camera​

Start Camera Scan​

To start the Document Scanner you only have to call DocutainSdk.scanDocument and wait for it to return.

An instance of DocumentScannerConfiguration can be used to launch the document scanner. It provides the possibility to change some behaviours to adapt it to your needs. See Change default scan behaviour for possible custom settings.

import de.docutain.sdk.kmp.DocutainException
import de.docutain.sdk.kmp.DocutainSdk
import de.docutain.sdk.kmp.DocumentScannerConfiguration

val scope = rememberCoroutineScope()
scope.launch {
try {
val scanConfig = DocumentScannerConfiguration()
val result = DocutainSdk.scanDocument(scanConfig)
if (result) {
// user finished scan process, continue with your workflow

// generate PDF
val pdf = DocutainSdk.writePDF()

// export the scanned pages as JPG
for (page in 1..DocutainSdk.pageCount()) {
val image = DocutainSdk.writeImage(page)
}

// get detected text
val text = DocutainSdk.getText()

// get extracted data
val data = DocutainSdk.analyze()
} else {
// user cancelled scan process
}
} catch (exception: DocutainException) {
// the SDK operation failed
}
}
info

The SDK operations used above are suspend functions. See Coroutines and suspend functions and Error Handling for details.

Scan from imported images​

It is also possible to use the Document Scanner on already taken images, for example images selected from the user's photo gallery. The process of starting the scanner on imported images is the same as when scanning with the camera. The only difference is defining a different Source in the DocumentScannerConfiguration. Possible values are:

ValueDescription
CAMERAStarts the Document Scanner using the device's camera. This is the default value.
CAMERA_IMPORTSame as CAMERA but shows an additional import button which the user can use to import files as well.
GALLERYOpens the user's photo gallery in single selection mode. The Document Scanner is run on the selected image.
GALLERY_MULTIPLEOpens the user's photo gallery in multi selection mode. The Document Scanner is run on the selected images.

The following sample shows how to open the photo gallery in multi selection mode and run the Document Scanner on the selected images:

import de.docutain.sdk.kmp.Source

val scanConfig = DocumentScannerConfiguration().apply {
source = Source.GALLERY_MULTIPLE
}

val scope = rememberCoroutineScope()
scope.launch {
val result = DocutainSdk.scanDocument(scanConfig)
}

Onboarding​

The SDK provides 2 optional onboarding possibilities that will be shown to the user on first start with some default content. You can customize it according to your needs or disable it completely.

See Onboarding for details.

onboardingDataProtection onboardingLightingConditions

Scan Tips​

The SDK provides an optional toolbar item within the scanning screen that, when clicked, will open some tips on how to get the best scan result. By default it is deactivated. You can enable it and show some default tips or customize it according to your needs.

See Scan Tips for details.

scanTips

Change default scan behaviour​

DocumentScannerConfiguration​

You can use the DocumentScannerConfiguration to alter the default scan behaviour to your needs. Currently the following values can be set from shared code:

PropertyTypeDefault ValueDescription
allowCaptureModeSettingBooleanfalseIf true, the document scanner toolbar will display an item that allows the user to switch between automatic and manual camera triggering.
autoCaptureBooleantrueIf true, the camera will capture the image automatically at the right moment.
defaultScanFilterScanFilterILLUSTRATIONThe default scan filter that will be used after scan. See ScanFilter for possible values.
pageEditConfigPageEditConfigurationPageEditConfigurationConfiguration class used to alter the default page editing behaviour.
sourceSourceCAMERAThe source of the Document Scanner. See Scan from imported images for more details.
autoCropBooleantrueIf true, the image gets automatically cropped if a document was detected. This applies only when importing images.
multiPageBooleantrueIf true, scanning multi page documents is possible. Set this to false if you need to scan single page documents.
preCaptureFocusBooleantrueIf true, the camera will run a focus action right before taking the image. This improves the quality of the scanned images, but depending on the device, image capture might take a little bit longer. Used for Android only.
textConfigTextConfigurationTextConfigurationConfiguration class used to alter the default text behaviour.
buttonConfigButtonConfigurationButtonConfigurationConfiguration class used to alter the default buttons.
colorConfigColorConfigurationColorConfigurationConfiguration class used to alter the default color theming behaviour.
confirmPagesBooleanfalseIf true, a list of all pages (thumbnails) will be displayed before the scan process can be finished.
allowPageEditingBooleantrueIf true, after the scan screen is finished, an editing screen with the captured images will be displayed.
statusBarAppearanceStatusBarAppearance?nullOverrides the status bar appearance. This only applies to Android.
navigationBarAppearanceNavigationBarAppearance?nullOverrides the navigation bar appearance. This only applies to Android.
onboardingOnboarding?SDK defaultAn optional onboarding when the user opens the scanner for the first time. See Onboarding.
scanTipsScanTips?nullAn optional toolbar item that shows scan tips when clicked. Disabled by default for the document scanner. See Scan Tips.
vibrateOnCaptureBooleanfalseIf true, the device vibrates to signal successful capture.
info

All parameters in DocumentScannerConfiguration are optional.

The following sample shows how to activate the confirmation mode:

val scanConfig = DocumentScannerConfiguration().apply {
confirmPages = true
}
val scope = rememberCoroutineScope()
scope.launch {
val result = DocutainSdk.scanDocument(scanConfig)
}

ScanFilter​

The defaultScanFilter determines which filter is applied to a page after it has been scanned. The user can still change it on the editing screen, unless you disabled the filter functionality via the PageEditConfiguration.

ValueDescription
ILLUSTRATIONOptimized for pages that also contain images. This is the default.
AUTOAutomatic filter selection.
AUTO2Alternative automatic filter selection.
TEXTOptimized for pages that contain text only.
GRAYGrayscale.
BLACKWHITEBlack and white. Pages are stored as single channel TIFF, which results in extremely small file sizes.
ORIGINALNo filter, the unmodified image.

PageEditConfiguration​

You can use the PageEditConfiguration to alter the default page editing behaviour of the document scanner to your needs. Currently the following values can be set:

PropertyTypeDefault ValueDescription
allowPageFilterBooleantrueIf false, the bottom toolbar will hide the filter page item.
allowPageRotationBooleantrueIf false, the bottom toolbar will hide the rotate page item.
allowPageArrangementBooleantrueIf false, the bottom toolbar will hide the arrange page item.
allowPageCroppingBooleantrueIf false, the bottom toolbar will hide the page cropping item.
allowPageRetakeBooleanfalseIf true, the bottom toolbar will show a button allowing to retake the current page.
allowPageAddBooleanfalseIf true, the bottom toolbar will show a button allowing to add a new page.
allowPageDeletionBooleantrueIf true, the menu item for deleting pages will be displayed in the toolbar.
pageArrangementShowDeleteButtonBooleanfalseIf true, each item of the page arrangement functionality will show a delete button.
pageArrangementShowPageNumberBooleantrueIf true, each item of the page arrangement functionality will show its page number.
info

All parameters in PageEditConfiguration are optional.

The following sample shows how to activate the page retake button:

val scanConfig = DocumentScannerConfiguration().apply {
pageEditConfig.allowPageRetake = true
}
val scope = rememberCoroutineScope()
scope.launch {
val result = DocutainSdk.scanDocument(scanConfig)
}

TextConfiguration​

You can use the TextConfiguration to alter the default text behaviour of the document scanner to your needs. If a value does not get set explicitly, the default value provided by the SDK will be used. Currently the following values can be set:

PropertyTypeDescription
textSizeBottomToolbarFloat?The text size of elements residing in the bottom toolbar.
textSizeTopToolbarFloat?The text size of menu items residing in the top toolbar.
textSizeScanButtonsFloat?The text size of the buttons in the scan page, located at the lower part, like the torch button.
textSizeTitleFloat?The text size of the title in the top toolbar. By default, auto shrinking down till 9.0 is enabled. If you define your custom size, automatic shrinking will be disabled.
textTitleScanPageString?The title to be displayed in the scan page top toolbar.
textTitleEditPageString?The title to be displayed in the edit page top toolbar.
textTitleFilterPageString?The title to be displayed in the filter page top toolbar.
textTitleCroppingPageString?The title to be displayed in the cropping page top toolbar.
textTitleArrangementPageString?The title to be displayed in the page arrangement page top toolbar.
textTitleConfirmationPageString?The title to be displayed in the confirmation page top toolbar.
textDocumentTitleString?The title to show in the top toolbar on all pages. It overwrites page specific titles, if any are set.
textFocusHintString?The text to show when camera is focusing after capture got triggered.
textFirstPageHintString?The text to show when user swipes to the previous page but is already at the first page.
textLastPageHintString?The text to show when user swipes to the next page but is already at the last page.
textOnePageHintString?The text to show when user swipes but only one page is available.
textScanProgressString?The text to show in the progress popup while pages are still being processed.
textDeleteDialogCurrentPageStringThe text for the option to delete the current page.
textDeleteDialogAllPagesStringThe text for the option to delete all pages.
textDeleteDialogCancelString?The text for the cancel option.
textTitleScanTipsPageString?The title to be displayed in the scan tips page top toolbar.
info

All parameters in TextConfiguration are optional.

The following sample shows how to set a document title:

val scanConfig = DocumentScannerConfiguration().apply {
textConfig.textDocumentTitle = "Document Title"
}
val scope = rememberCoroutineScope()
scope.launch {
val result = DocutainSdk.scanDocument(scanConfig)
}

ButtonConfiguration​

You can use the ButtonConfiguration to alter the default buttons of the scanner. Each button is an object of DocutainButton; its title can be changed from shared code.

Currently the following buttons can be set:

ButtonDefault ValueDescription
buttonEditRotatebuttonEditRotateThe button that rotates the current page.
buttonEditCropbuttonEditCropThe button that opens the cropping functionality.
buttonEditFilterbuttonEditFilterThe button that opens the filter functionality.
buttonEditArrangebuttonEditArrangeThe button that opens the page arrangement functionality.
buttonEditRetakebuttonEditRetakeThe button that starts the process of replacing the current page with a new scan.
buttonEditAddPagebuttonEditAddPageThe button on the edit page that opens the scan screen to add a new page.
buttonEditDeletebuttonEditDeleteThe button that deletes the current page or opens a dialog with options if multiple pages are available.
buttonEditFinishbuttonEditFinishThe button that finishes the scan process.
buttonCropExpandbuttonCropExpandThe button that expands the cropping rectangle to the whole page.
buttonCropSnapbuttonCropSnapThe button that snaps the cropping rectangle to the detected document.
buttonCropFinishbuttonCropFinishThe button that finishes the manual cropping process.
buttonScanAutoCaptureOnbuttonScanAutoCaptureOnThe button shown when automatic capture is activated.
buttonScanAutoCaptureOffbuttonScanAutoCaptureOffThe button shown when automatic capture is deactivated.
buttonScanTorchbuttonScanTorchThe button that toggles the torch.
buttonScanCapturebuttonScanCaptureThe button that triggers a manual image capture.
buttonScanFinishbuttonScanFinishThe button that finishes the current scan process.
buttonScanImportbuttonScanImportThe button that opens a file importer.
buttonConfirmationFinishbuttonConfirmationFinishThe button that finishes the confirmation page.

On iOS, shared code can also configure two cancel buttons:

FunctionDescription
configureEditCancelImportConfigures the button that cancels importing from the edit page.
configureScanCancelConfigures the button that cancels the current scan.
import de.docutain.sdk.kmp.configureEditCancelImport
import de.docutain.sdk.kmp.configureScanCancel

val scanConfig = DocumentScannerConfiguration().apply {
buttonConfig.configureEditCancelImport { title = "Cancel import" }
buttonConfig.configureScanCancel { title = "Cancel scan" }
}
val scope = rememberCoroutineScope()
scope.launch {
DocutainSdk.scanDocument(scanConfig)
}
info

All parameters in ButtonConfiguration are optional.

The following sample shows how to customize buttonEditRotate:

val scanConfig = DocumentScannerConfiguration().apply {
buttonConfig.buttonEditRotate.title = "Rotate"
}
val scope = rememberCoroutineScope()
scope.launch {
val result = DocutainSdk.scanDocument(scanConfig)
}

ColorConfiguration​

In order to fit the Docutain Scanner SDK for Kotlin Multiplatform into your corporate design, you have a bunch of options to alter the default color theming of the ready-to-use UI components. See color configuration for details.

Result handling​

After the scan process is successfully finished, you can do a bunch of things with the scanned pages:

Kotlin Multiplatform PDF Creation

Kotlin Multiplatform Image Export

Kotlin Multiplatform Text Recognition

Kotlin Multiplatform Data Extraction

Language Support​

The device's locale determines the languages used by the Docutain SDK.

Currently, the SDK provides default translations for the following languages:

  • English
  • Arabic
  • Bulgarian
  • Chinese, Simplified
  • Chinese, Traditional
  • Croatian
  • Czech
  • Danish
  • Dutch
  • Finnish
  • French
  • German
  • Greek
  • Hindi
  • Hungarian
  • Icelandic
  • Indonesian
  • Italian
  • Japanese
  • Korean
  • Lithuanian
  • Norwegian Bokmal
  • Polish
  • Portuguese
  • Portuguese (Brazil)
  • Romanian
  • Russian
  • Serbian
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Turkish

The fallback language is English. It is used for all device locales not listed above.