Skip to main content

Document Scan

The Docutain Document Scanner SDK for .NET MAUI comes with integrated, ready to use UI components for the document scan process. Colors and icons can be changed to match your branding.

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

ScanEditPreview

Initialization

Initialize the Docutain .NET MAUI Scanner SDK as described here.

Scan with Camera

Camera Permission

Android

Declare the following permission in your AndroidManifest.xml.

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
info

Runtime permission for camera is handled automatically by the Docutain SDK.

iOS

You need to specify the reason for requesting access to the camera as part of the NSCameraUsageDescription in the Info.plist. If you don't the app will crash.

NSCameraUsageDescription

Start Camera Scan

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

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

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
var result = await UI.ScanDocument(scanConfig);
if(result)
{
//user finished scan process, continue with your workflow
//generate PDF
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdf = Document.WritePDF(destinationPath);
//get detected Text
var text = DocumentDataReader.GetText();
//get extracted data
var data = DocumentDataReader.Analyze();
}
else
{
//user canceled scan process
}

Scan from imported images

It is also possible to use the Document Scanner on already taken images, for example images selected from the users 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:

  • Camera : This is the default value. Starts the Document Scanner using the devices camera.
  • Image : Starts the Document Scanner on images provided by you via code. Pass SourceImages to the DocumentScannerConfiguration containing the paths to the images to be scanned.
  • Gallery : Opens the user's photo gallery in single select mode. The Document Scanner is run on the selected image.
  • GalleryMultiple : Opens the user's photo gallery in multi select mode. The Document Scanner is run on the selected images.

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

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.Source = Source.GalleryMultiple;
var result = await UI.ScanDocument(scanConfig);
if(result)
{
//user finished scan process, continue with your workflow
//generate PDF
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdf = Document.WritePDF(destinationPath);
//get detected Text
var text = DocumentDataReader.GetText();
//get extracted data
var data = DocumentDataReader.Analyze();
}
else
{
//user canceled scan process
}

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:

PropertyTypeDefault ValueDescription
AllowCaptureModeSettingboolfalseIf true, the document scanner toolbar will display an item that allows the user to switch between automatic and manual camera triggering.
AutoCapturebooltrueIf true, the camera will capture the image automatically at the right moment.
DefaultScanFilterScanFilterIllustrationThe default scan filter that will be used after scan.
OnboardingImageSourcestringnullYour custom image for the onboarding dialog that appears when scan is opened for the first time. Set it to the image name you want to use. If it is a SVG or PNG image, you need to leave out the file extension. If it is a JPG image, you need to provide the file extension for the iOS platform and leave out the file extension for the Android platform.
PageEditConfigPageEditConfigurationPageEditConfigurationConfiguration class used to alter the default page editing behaviour. See PageEditConfiguration for more details.
SourceSourceCameraThe source of the Document Scanner. If you need to run the scanner on imported images please see Scan from imported images for more details.
SourceImagesList<string>empty listPlease see Scan from imported images for more details.
AutoCropbooltrueIf true, image gets automatically cropped if document was detected. This applies only when importing images.
MultiPagebooltrueIf true, scanning multi page documents is possible. Set this to false if you need to scan single page documents.
PreCaptureFocusbooltrueIf 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. See TextConfiguration for more details.
ButtonConfigButtonConfigurationButtonConfigurationConfiguration class used to alter the default buttons. See ButtonConfiguration for more details.
ConfirmPagesboolfalseIf true, a list of all pages (thumbnails) will be displayed before the scan process can be finished.
AllowPageEditingbooltrueIf true, after the scan screen is finished, an editing screen with the captured images will be displayed. On the editing screen, the user can crop manually, rotate the page, filter the page and much more. The editing screen can be configured by accessing the PageEditConfiguration.
info

All parameters in DocumentScannerConfiguration are optional.


The following sample shows how to activate the confirmation mode:

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.ConfirmPages = true;
var result = await UI.ScanDocument(scanConfig);

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
AllowPageFilterbooltrueIf false, the bottom toolbar will hide the filter page item.
AllowPageRotationbooltrueIf false, the bottom toolbar will hide the rotate page item.
AllowPageArrangementbooltrueIf false, the bottom toolbar will hide the arrange page item.
AllowPageCroppingbooltrueIf false, the bottom toolbar will hide the page cropping item.
AllowPageRetakeboolfalseIf true, the bottom toolbar will show a button allowing to retake the current page.
PageArrangementShowDeleteButtonboolfalseIf true, each item of the page arrangement functionality will show a delete button.
PageArrangementShowPageNumberbooltrueIf true, each item of the page arrangement functionality will show it's page number.
info

All parameters in PageEditConfiguration are optional.


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

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.PageEditConfig.AllowPageRetake = true;
var result = await UI.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. If you set a text value to string.Empty, it won't show any text. You can use this to remove predefined text. 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.
TextTitleScanPagestringThe title to be displayed in the scan page top toolbar.
TextTitleEditPagestringThe title to be displayed in the edit page top toolbar.
TextTitleFilterPagestringThe title to be displayed in the filter page top toolbar.
TextTitleCroppingPagestringThe title to be displayed in the cropping page top toolbar.
TextTitleArrangementPagestringThe title to be displayed in the page arrangement page top toolbar.
TextTitleConfirmationPagestringThe title to be displayed in the confirmation page top toolbar.
TextDocumentTitlestringThe title to show in the top toolbar on all pages. It overwrites page specific titles, if any are set.
TextOnboardingTitlestringThe text to show in the onboarding popup title that appears when the scan page is opened for the first time.
TextOnboardingMessagestringThe text to show in the onboarding popup message that appears when the scan page is opened for the first time.
TextOnboardingCloseButtonstringThe text to show in the onboarding popup close button that appears when the scan page is opened for the first time.
TextSizeOnboardingTitlefloat?The text size of the onboarding popup title that appears when the scan page is opened for the first time.
TextSizeOnboardingMessagefloat?The text size of the onboarding popup message that appears when the scan page is opened for the first time.
TextFocusHintstringThe text to show when camera is focusing after capture got triggered.
TextFirstPageHintstringThe text to show when user swipes to previous page but is already at the first page.
TextLastPageHintstringThe text to show when user swipes to next page but is already at the last page.
TextOnePageHintstringThe text to show when user swipes to next or previous page but only one page is available.
TextScanProgressstringThe text to show in the progress popup that is shown when user clicks the done button but some pages still need to be processed.
TextDeleteDialogCurrentPagestringThe text to show for the option to delete the current page within the dialog that will be shown when clicking delete while multiple pages are available.
TextDeleteDialogAllPagesstringThe text to show for the option to delete all pages within the dialog that will be shown when clicking delete while multiple pages are available.
TextDeleteDialogCancelstringThe text to show for the option to cancel within the dialog that will be shown when clicking delete while multiple pages are available.
info

All parameters in TextConfiguration are optional.


The following sample shows how to set a document title:

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.TextConfig.TextDocumentTitle = "Document Title";
var result = await UI.ScanDocument(scanConfig);

ButtonConfiguration

You can use the ButtonConfiguration to alter the default buttons of the scanner. Each button is an object of DocutainButton and has a Title and Icon property. Buttons residing in the top toolbar can have either a title or an icon. If you define both, the icon will be displayed. Buttons residing in the bottom toolbar can have both title and icon at the same time. If you want a button to only display text, set the Icon property to null and the Title property to the text you want to display. If you want a button to only display an icon, set the Title property to null and the Icon property to the icon you want to display.

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.
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 within the cropping functionality that expands the current cropping rectangle to the whole page.
ButtonCropSnapbuttonCropSnapThe button within the cropping functionality that snaps the current cropping rectangle to the detected document.
ButtonCropFinishbuttonCropFinishThe button within the cropping functionality that finishes the manual cropping process according to the current cropping rectangle.
ButtonScanAutoCaptureOnbuttonScanAutoCaptureOnThe button within the scan functionality that is shown when automatic capture is activated.
ButtonScanAutoCaptureOffbuttonScanAutoCaptureOffThe button within the scan functionality that is shown when automatic capture is deactivated.
ButtonScanTorchbuttonScanTorchThe button within the scan functionality that toggles the torch.
ButtonScanCapturebuttonScanCaptureThe button within the scan functionality that triggers a manual image capture.
ButtonScanFinishbuttonScanFinishThe button within the scan functionality that finishes the current scan process and leads to the editing page.
ButtonConfirmationFinishbuttonConfirmationFinishThe button on the confirmation page that finishes the scan process.
info

All parameters in ButtonConfiguration are optional.


The following sample shows how to customize the ButtonEditRotate:

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.ButtonConfig.ButtonEditRotate.Title = "Custom Title";
scanConfig.ButtonConfig.ButtonEditRotate.Icon = "custom_icon";
var result = await UI.ScanDocument(scanConfig);

ColorConfiguration

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

Supported colors

The following is a list of all colors currently supported.

ColorDefault ValueDescription
ColorPrimarylight: #4CAF50
dark: #4CAF50
Used to tint progress indicators and dialog buttons. theming_dialog_button theming_progress_indicators
ColorSecondarylight: #4CAF50
dark: #4CAF50
Used to tint selectable controls and the capture button. theming_selection_controls
theming_capture_button
ColorOnSecondarylight: #FFFFFF
dark: #000000
Used to tint elements that reside on ColorSecondary, like the icon of the capture button.
theming_capture_button
ColorScanButtonsLayoutBackgroundlight: #121212
dark: #121212
Used to tint the background of the scan buttons layout.
theming_scan_buttons_layout
ColorScanButtonsForegroundlight: #FFFFFF
dark: #FFFFFF
Used to tint the foreground of the scan buttons layout, like the torch button.
theming_scan_buttons_layout
ColorScanPolygonlight: #4CAF50
dark: #4CAF50
Used to tint the polygon overlay which highlights the currently detected document.
theming_scan_polygon
ColorBottomBarBackgroundlight: #FFFFFF
dark: #212121
Used to tint the bottom toolbar background of the image editing page.
theming_edit_bottombar
ColorBottomBarForegroundlight: #323232
dark: #BEBEBE
Used to tint the buttons within the bottom toolbar of the image editing page.
theming_edit_bottombar
ColorTopBarBackgroundlight: #4CAF50
dark: #2a2a2a
Used to tint the top toolbar background. theming_topbar
ColorTopBarForegroundlight: #FFFFFF
dark: #DEFFFFFF
Used to tint the buttons contained in the top toolbar. theming_topbar
ColorTopBarTitlelight: #FFFFFF
dark: #DEFFFFFF
Used to tint the text of the top toolbar title. theming_topbar_title

The following sample shows how to customize the ColorSecondary:

using Docutain.SDK.MAUI;

var scanConfig = new DocumentScannerConfiguration();
scanConfig.ColorConfig.ColorSecondary = (Colors.Orange, Colors.Red);
var result = await UI.ScanDocument(scanConfig);

Dark Mode

The Docutain Scanner SDK for MAUI also supports dark mode theming. The process is the same, just define different colors for the night version of your theme. The SDK decides which color to use depending on the device's sytem setting and it will change at runtime, if the device's display mode changes.

theming_edit_bottombar theming_edit_bottombar_dark

Result handling

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

.NET MAUI PDF Creation

.NET MAUI Text Detection

.NET MAUI 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
  • Croation
  • Czech
  • Danish
  • Dutch
  • Finnish
  • French
  • German
  • Greek
  • Hindi
  • Hungarian
  • Icelandic
  • Indonesian
  • Italian
  • Japanese
  • Korean
  • Lithuanian
  • Norwegian Bokmal
  • Polish
  • Portugese
  • Portugese (Brazil)
  • Romanian
  • Russian
  • Serbian
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Turkish

The fallback language is English. This means if the device is set to a language that is currently not supported, it will show English texts.