Skip to main content

SDK Features | .NET Document Scanner

Integration with ScanbotSDK.NET

The NuGet package ScanbotSDK.NET is a universal package for Android and iOS. It contains the MAUI Bindings for the Native Scanbot SDKs for Android and iOS and the Wrappers.


The bindings for Native SDKs and the Wrappers are stored in different namespaces which are explained here.

ScanbotSDK.NET Wrapper

  • Namespace for Android: ScanbotSDK.MAUI.Native.Droid
  • Namespace for iOS: ScanbotSDK.MAUI.Native.iOS

The idea of the ScanbotSDK.NET Wrapper is to provide a unified and convenient API for iOS and Android. However, since not all Native SDK functionalities are available in the Wrapper namespace, you can use and call them as needed directly from the native namespaces.

Currently the following Package II functionalities are available for the .NET Wrapper classes:

  • Document detection on images
  • Image processing (cropping and perspective correction, rotating, etc)
  • Image filters
  • PDF creation
  • TIFF creation
  • Text Recognition (OCR)

Native SDKs

Native SDKs for Android and iOS are provided as MAUI Bindings Libraries and can be found in these namespaces:

  • Android: Net.Doo.Snap, IO.Scanbot.Sdk
  • iOS: ScanbotSDK.iOS

The MAUI Bindings for the Native SDKs provide the most available functionality of the Scanbot SDK.

👉 Documentation for Native SDKs classes can be found here:

Scanbot SDK RTU UI Components

The Ready-To-Use UI (RTU UI) is a set of easy to integrate and customize high-level UI components (View Controllers for iOS and Activities for Android) for the most common tasks in Scanbot SDK. The design and behavior of these RTU UI Components are based on our many years of experience as well as the feedback from our SDK customers.

The following RTU UI Components and classes are currently provided:


  • Document Scanner - DocumentScannerActivity
  • Cropping - CroppingActivity
  • MRZ Scanner - MRZScannerActivity
  • Barcode and QR-Code Scanner - BarcodeScannerActivity & BatchBarcodeScannerActivity
  • Generic Document Recognizer - GenericDocumentRecognizerActivity
  • European Health Insurance Card Scanner - HealthInsuranceCardScannerActivity
  • Check Recognizer - CheckRecognizerActivity


  • Document Scanner - SBSDKUIDocumentScannerViewController
  • Cropping - SBSDKUICroppingViewController
  • MRZ Scanner - SBSDKUIMRZScannerViewController
  • Barcode and QR-Code Scanner - SBSDKUIBarcodeScannerViewController & SBSDKUIBarcodesBatchScannerViewController
  • European Health Insurance Card Scanner - SBSDKUIHealthInsuranceCardScannerViewController
  • Check Recognizer - SBSDKUICheckRecognizerViewController

For more details please see the corresponding API docs of the classes as well as our example app.

Customization of RTU UI:

The main idea of the RTU UI is to provide simple-to-integrate and simple-to-customize screen components. Due to this idea there are some limitations with the possibilities of customization:

  • UI: All colors and text resources (localization)
  • Behavior: Enable or disable features like Multi-Page Scanning, Auto Snapping, Flashlight

RTU UI Examples:

Please see our example app scanbot-sdk-maui-example on GitHub.

SDK Feature Overview

Barcode Scanner

The Scanbot SDK comes with an essential camera view, additional views for extending the camera functionality and a detector classes that handle all the camera and detection implementation details for you.

It provides a UI for document scanning guidance as well as a UI and functionality for manual and automatic shutter release on barcode detection.

Scanning Single Barcodes

Launches the barcode scanner. The scanned code will be returned asynchronously.


Batch Barcode Scanning

Launches the batch barcode scanner. The scanned codes will be returned asynchronously.


Detection on the Image

The Scanbot SDK detects barcodes from an existing image (UIImage or Bitmap). Result format is equivalent to Barcode Scanner

var SDK = new IO.Scanbot.Sdk.ScanbotSDK(context);
BarcodeScanningResult result = SDK.BarcodeDetector().DetectFromBitmap(bitmap, 0);

Document Scanner

The Scanbot SDK uses digital image processing algorithms to find rectangular, document like polygons in a digital image. As input a UIImage on iOS or Bitmap on Android are accepted.

Bitmap image = ...; // on Android
UIImage image = ...; // on iOS

var detectionResult = ScanbotSDK.DetectDocument(image);
if (detectionResult.Status == DocumentDetectionStatus.Ok)
var resultImage = detectionResult.Image as Bitmap; // on Android
var resultImage = detectionResult.Image as UIImage; // on iOS
var polygon = detectionResult.Polygon;

The result is an object of type DocumentDetectionResult which contains the detection status and on success the warped and cropped document image as well as the detected polygon. If there was no document detected the status enum provides the reason (noisy background, too dark, etc). The polygon is a list with 4 float points (one for each corner). Each point has coordinates in the range [0..1], representing a position relative to the image size. For instance, if a point has the coordinates (0.5, 0.5), it means that it is located exactly in the center of the image.

Alternatively, you can pass a Uri on Android or NSUrl on iOS of the source image.

public static DocumentDetectionResult DetectDocument(Android.Net.Uri imageUri, Android.Content.Context context)

User Guidance

The Scanbot SDK provides UI components for guided, automatic document scanning. These component classes handle all the camera and detection implementation details for you and can be used in your app. It is possible to customize the appearance and behavior of the guidance UI.

In the following examples we use the classes from the Native SDK namespaces. Please make sure that you have defined the required permissions in your app.

The Android camera API might seem to be very tricky and far from being developer-friendly. To help you skip the same issues which we encountered while developing Scanbot we created ScanbotCameraView. You can use it in your app's Activity or Fragment. ScanbotCameraView has a method getPreviewBuffer() which allows you to register for preview frames from the camera. While you can implement your own smart features, Scanbot SDK comes with the built-in ContourDetectorFrameHandler which performs contour detection (document detection) and outputs results to listeners. To draw detected contours, the Scanbot SDK provides the class PolygonView. To further improve the user experience you might want to automatically take a photo when a document is detected and conditions are good - we call this Autosnapping. For this purpose we have the AutoSnappingController class.

NOTE: You can also use ScanbotCameraXView instead of ScanbotCameraView, which uses CameraX under the hood.

The following example demonstrates the use of all modules.

Example layout for a Scanner Camera Activity MyCameraView.axml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android=""
app:polygonFillColor="#55009688" />
android:layout_gravity="bottom|right" />
android:text="Snap" />
android:text="Flash" />
android:layout_gravity="center_vertical|center_horizontal" />

And the Scanner Camera Activity class:

using Android.App;
using Android.Graphics;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V7.App;
using Android.Widget;

// native SDK namespace
using Net.Doo.Snap.Camera;
using Net.Doo.Snap.Lib.Detector;
using Net.Doo.Snap.UI;

// Wrapper namespace
using DocumentSDK.MAUI;
using DocumentSDK.MAUI.Native.Droid;

[Activity(Theme = "@style/Theme.AppCompat")]
public class MyCameraActivity : AppCompatActivity, IPictureCallback, ContourDetectorFrameHandler.IResultHandler, ICameraOpenCallback
protected ScanbotCameraView cameraView;
protected AutoSnappingController autoSnappingController;
protected bool flashEnabled = false;
protected ImageView resultImageView;
protected TextView userGuidanceTextView;

protected override void OnCreate(Bundle savedInstanceState)

// Use our example view (MyCameraView.axml)


cameraView = FindViewById<ScanbotCameraView>(Resource.Id.scanbotCameraView);
resultImageView = FindViewById<ImageView>(Resource.Id.scanbotResultImageView);

userGuidanceTextView = FindViewById<TextView>(Resource.Id.userGuidanceTextView);

ContourDetectorFrameHandler contourDetectorFrameHandler = ContourDetectorFrameHandler.Attach(cameraView);
PolygonView polygonView = FindViewById<PolygonView>(Resource.Id.scanbotPolygonView);
autoSnappingController = AutoSnappingController.Attach(cameraView, contourDetectorFrameHandler);
// Set the sensitivity of AutoSnappingController
// Range is from 0 to 1, where 1 is the most sensitive. The more sensitive it is the faster it shoots.


FindViewById(Resource.Id.scanbotSnapButton).Click += delegate {

FindViewById(Resource.Id.scanbotFlashButton).Click += delegate {
flashEnabled = !flashEnabled;

protected override void OnResume()

protected override void OnPause()

public void OnCameraOpened()
cameraView.PostDelayed(() => {
// Enable continuous focus mode
}, 300);

public bool HandleResult(ContourDetectorFrameHandler.DetectedFrame result)
// Here you are continuously notified about contour detection results.
// For example, you can set a localized text for user guidance depending on the detection status.

var color = Color.Red;
var guideText = "Get closer...";

if (result.Polygon == null || result.Polygon.Count == 0) {
guideText = "Searching for document...";

if (result.DetectionResult == DetectionResult.Ok) {
guideText = "OK, don't move.";
color = Color.Green;
// else ...

// Warning: The HandleResult callback is coming from a worker thread. Use main UI thread to update the UI elements.
userGuidanceTextView.Post(() => {
userGuidanceTextView.Text = guideText;

return false;

public void OnPictureTaken(byte[] image, int imageOrientation)
// Here we get the full image from the camera.

// decode bytes as Bitmap
BitmapFactory.Options options = new BitmapFactory.Options();
//options.InSampleSize = 1; // use 1 for original size (if you want no downscale)
// to save memory for the preview image here we use smaller image (inSampleSize = 8 returns an image that is 1/8 the width/height of the original)!
options.InSampleSize = 8;
Bitmap bitmap = BitmapFactory.DecodeByteArray(image, 0, image.Length, options);

// Run document detection on image:
var detectionResult = ScanbotSDK.DocumentDetection(bitmap);
if (detectionResult.Status.IsOk())
var documentImage = detectionResult.Image as Bitmap;
// Do whatever you want with the documentImage...
resultImageView.Post(() => {
// continue camera preview with continuous focus mode

Image Cropping

The Scanbot SDK provides some smart elements like magnetic lines or magnifier to build a UI for manual cropping of images.

In the following examples we use the classes from the native SDK namespaces.

Example code for an Activity:

Activity layout MyCroppingView.axml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android=""
app:edgeColor="#0000ff" />
app:magnifierImageSrc="@drawable/ui_crop_magnifier" />

And the Activity class:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.App;
using Android.Graphics;
using Android.OS;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;

// native SDK namespace
using Net.Doo.Snap.Lib.Detector;
using Net.Doo.Snap.UI;

[Activity(Theme = "@style/Theme.AppCompat")]
public class MyCroppingActivity : AppCompatActivity
static IList<Android.Graphics.PointF> DEFAULT_POLYGON = new List<Android.Graphics.PointF>();
static MyCroppingActivity()
DEFAULT_POLYGON.Add(new Android.Graphics.PointF(0, 0));
DEFAULT_POLYGON.Add(new Android.Graphics.PointF(1, 0));
DEFAULT_POLYGON.Add(new Android.Graphics.PointF(1f, 1f));
DEFAULT_POLYGON.Add(new Android.Graphics.PointF(0, 1));

private Bitmap image; // original source image
private EditPolygonImageView editPolygonImageView;
private MagnifierView scanbotMagnifierView;
private View cancelBtn, saveBtn;

protected override void OnCreate(Bundle savedInstanceState)



editPolygonImageView = FindViewById<EditPolygonImageView>(Resource.Id.scanbotEditImageView);
scanbotMagnifierView = FindViewById<MagnifierView>(Resource.Id.scanbotMagnifierView);

cancelBtn = FindViewById<View>(Resource.Id.cancelButton);
cancelBtn.Click += delegate {

saveBtn = FindViewById<View>(Resource.Id.doneButton);
saveBtn.Click += delegate {


void initImageView()
Task.Run(() => {
try {
image = ...; // get/load your original source image

// it is recommended to use a resized (thumbnail) image for the ImageView and ContourDetector:
Bitmap thumbBitmap = ...; // scale your image down to a suitable size

RunOnUiThread(() => {
// important: first set the image and then the detected polygon and lines!
// set up the MagnifierView every time editPolygonImageView is set with a new image.

// perform edge and lines detection:
ContourDetector detector = new ContourDetector();
DetectionResult detectionResult = detector.Detect(thumbBitmap);

var polygon = DEFAULT_POLYGON;
if (detectionResult == DetectionResult.Ok || detectionResult == DetectionResult.OkButBadAngles ||
detectionResult == DetectionResult.OkButTooSmall || detectionResult == DetectionResult.OkButBadAspectRatio)
// get detected polygon
polygon = detector.PolygonF;

RunOnUiThread(() => {
// set the detected polygon and lines:
editPolygonImageView.Polygon = polygon;
editPolygonImageView.SetLines(detector.HorizontalLines, detector.VerticalLines);
catch (Exception e) {
// error handling


void cropAndSaveImage()
Task.Run(() => {
try {
// crop and warp the image by detected/changed polygon:
ContourDetector detector = new ContourDetector();
Bitmap documentImage = detector.ProcessImageF(image, editPolygonImageView.Polygon, ContourDetector.ImageFilterNone);
// save the documentImage...
catch (Exception e) {
// error handling

RunOnUiThread(() => {


Image Filtering

Bitmap image = ...; // on Android
UIImage image = ...; // on iOS
var resultImage = ScanbotSDK.ApplyImageFilter(image, ImageFilter.Binarized);

Supported image filters:

  • ImageFilter.ColorEnhanced - Optimizes colors, contrast and brightness.
  • ImageFilter.Grayscale - Grayscale filter
  • ImageFilter.Binarized - Standard binarization filter with contrast optimization. Creates an 8-bit grayscale image with mostly black or white pixels.
  • ImageFilter.ColorDocument - MagicColor filter. Fixes white balance and cleans up the background.
  • ImageFilter.PureBinarized - A filter for binarizing an image. Creates an image with pixel values set to either pure black or pure white.
  • ImageFilter.BackgroundClean - Cleans up the background and tries to preserve photos within the image.
  • ImageFilter.BlackAndWhite - Black and white filter with background cleaning. Creates an 8-bit grayscale image with mostly black or white pixels.
  • ImageFilter.OtsuBinarization - A filter for black and white conversion using OTSU binarization.
  • ImageFilter.DeepBinarization - A filter for black and white conversion primary used for low contrast documents.
  • ImageFilter.EdgeHighlight - A filter that enhances edges in low contrast documents.
  • ImageFilter.LowLightBinarization - A binarization filter primarily intended for use on low contrast documents with hard shadows.

Creating PDF Documents

The Scanbot SDK renders images into a PDF document and stores it as a given target file. For each image a separate page is generated.

Android.Net.Uri[] images = ...;
Android.Net.Uri pdfOutputFileUri = ...;
ScanbotSDK.CreatePDF(images, pdfOutputFileUri, PDFPageSize.FixedA4);

The following PDF page sizes are supported:

  • PDFPageSize.A4 - The page has the aspect ratio of the image, but is fitted within A4 size. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.FixedA4 - The page is A4 in size. The image is fitted and centered within the page. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.USLetter - The page has the aspect ratio of the image, but is fitted within US letter size. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.FixedUsLetter - The page is US letter in size. The image is fitted and centered within the page. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.Auto - For each page the best matching format (A4 or US letter) is used. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.AutoLocale - Each page of the result PDF will be of US letter or A4 size depending on the current locale. Portrait or landscape orientation is determined by the image's aspect ratio.
  • PDFPageSize.FromImage - Each page is as large as its image at 72 dpi.

EHIC Scanner

The Scanbot SDK detects and extracts data from European Health Insurance Cards.

var result = (HealthInsuranceCardRecognitionResult)Intent.GetParcelableExtra(

var fragment = HealthInsuranceCardFragment.CreateInstance(result);
fragment.Show(SupportFragmentManager, HealthInsuranceCardFragment.NAME);

Check Scanner

You can use the Check Recognizer UI to conveniently scan and extract data from checks.

// Launch the Check UI
var config = new CheckRecognizerConfiguration();
config.SetAcceptedCheckStandards(new List<IO.Scanbot.Check.Entity.RootDocumentType>
var intent = CheckRecognizerActivity.NewIntent(this, config);
StartActivityForResult(intent, Constants.CHECK_RECOGNIZER_REQUEST);

// Handle Result
if (requestCode == Constants.CHECK_RECOGNIZER_REQUEST)
var resultWrapper = (ResultWrapper)data.GetParcelableExtra(RtuConstants.ExtraKeyRtuResult);
var resultRepository = sdkInstance.ResultRepositoryForClass(resultWrapper.Clazz);
var checkResult = (CheckRecognizerResult)resultRepository.GetResultAndErase(resultWrapper.ResultId);
var fields = checkResult.Check.Fields;

// String representation example
var description = string.Join(";\n", fields
.Where(field => field != null)
.Select((field) =>
string outStr = "";
if (field.GetType() != null && field.GetType().Name != null)
outStr += field.GetType().Name + " = ";
if (field.Value != null && field.Value.Text != null)
outStr += field.Value.Text;
return outStr;

Console.WriteLine("Check Recognizer Result: ", description);

Optical Character Recognition

The Scanbot SDK provide simple and convenient APIs to run Optical Character Recognition (OCR) on images.

As result you can get:

  • a searchable PDF document with the recognized text layer (aka. sandwiched PDF document)
  • recognized text as plain text,
  • bounding boxes of all recognized paragraphs, lines and words,
  • text results and confidence values for each bounding box.

The Scanbot OCR feature is based on the Tesseract OCR engine with some modifications and enhancements. The OCR engine supports a wide variety of languages. For each desired language a corresponding OCR training data file (.traineddata) must be provided. Furthermore, the special data file osd.traineddata is required (used for orientation and script detection). The Scanbot SDK package contains no language data files to keep the SDK small in size. You have to download and include the desired language files in your app.

Preconditions to achieve a good OCR result

Conditions while scanning

A perfect document for OCR is flat, straight, in the highest possible resolution and does not contain large shadows, folds, or any other objects that could distract the recognizer. Our UI and algorithms do their best to help you meet these requirements. But as in photography, you can never fully get the image information back that was lost during the shot.


You can use multiple languages for OCR. But since the recognition of characters and words is a very complicated process, increasing the number of languages lowers the overall precision. With more languages, there are more results where the detected word could match. We suggest using as few languages as possible. Make sure that the language you are trying to detect is supported by the SDK and added to the project.

Size and position

Put the document on a flat surface. Take the photo from straight above in parallel to the document to make sure that the perspective correction does not need to be applied much. The document should fill most of the camera frame while still showing all of the text that needs to be recognized. This results in more pixels for each character that needs to be detected and hence, more detail. Skewed pages decrease the recognition quality.

Light and shadows

More ambient light is always better. The camera takes the shot at a lower ISO value, which results in less grainy photos. You should make sure that there are no visible shadows. If you have large shadows, it is better to take the shot at an angle instead. We also do not recommend using the flashlight - from this low distance it creates a light spot at the center of the document which decreases the recognition quality.


The document needs to be properly focused so that the characters are sharp and clear. The autofocus of the camera works well if you meet the minimum required distance for the lens to be able to focus. This usually starts at 5-10cm.


The OCR trained data is optimized for common serif and sans-serif font types. Decorative or script fonts drastically decrease the quality of the recognition.

Download and Provide OCR Language Files

You can find a list of all supported OCR languages and download links on this Tesseract page.

⚠️️️ Please choose and download the proper version of the language data files:

Download the desired language files as well as the osd.traineddata file and place them in the Assets sub-folder SBSDKLanguageData/ of your Android app or in the Resources sub-folder ScanbotSDKOCRData.bundle/ of your iOS app.

Droid/Assets/SBSDKLanguageData/eng.traineddata  // english language file
Droid/Assets/SBSDKLanguageData/deu.traineddata // german language file
Droid/Assets/SBSDKLanguageData/osd.traineddata // required special data file


Android.Net.Uri[] images = ...;
Android.Net.Uri pdfOutputFileUri = ...;
OcrResult result = ScanbotSDK.PerformOCR(images, new []{ "en", "de" }, pdfOutputFileUri);

// recognized plain text
string text = result.recognizedText;

// bounding boxes and text results of recognized paragraphs, lines and words:
List<OcrResultBlock> paragraphs = result.Paragraphs;
List<OcrResultBlock> lines = result.Lines;
List<OcrResultBlock> words = result.Words;

See the API reference of the OcrResult class for more details.

Estimating Image Blurriness

var estimator = new IO.Scanbot.Sdk.ScanbotSDK(this).BlurEstimator();
var = estimator.EstimateInBitmap(bitmap, 0);

Less is sharper, more is blurred.

In board terms, consider blur values as follows:

  • 0.0-0.3: This image is not blurry at all
  • 0.3-0.6: Somewhat blurry, should be okay
  • 0.6-1.0: I am skeptical of the usefulness of the image

However, this is not as easy as it seems. If a scanned document has a predominantly white background, it will be considered a very blurred image. It is therefore best to use blur estimator in conjunction with a finder view or on an already cropped document.

DocumentDetectionStatus enum:

  • Ok - Document detection was successful. The detected contour looks like a valid document.
  • OkButTooSmall - Document was detected, but it does not fill the desired area in the camera viewport. The quality can be improved by moving the camera closer to the document.
  • OkButBadAngles - Document was detected, but the perspective is wrong (camera is tilted relative to the document). Quality can be improved by holding the camera directly over the document.
  • OkButBadAspectRatio - Document was detected, but it has a wrong rotation relative to the camera sensor. Quality can be improved by rotating the camera 90 degrees.
  • ErrorTooDark - Document was not found, most likely because of bad lighting conditions.
  • ErrorTooNoisy - Document was not found, most likely because there is too much background noise (maybe too many other objects on the table, or the background texture is not monotonic).
  • ErrorNothingDetected - Document was not found. It is probably not in the viewport. Usually, it does not make sense to show any information to the user at this point.

Storage and Encryption

Scanbot SDK provides the ability to store the generated image files (JPG, PNG) and PDF files encrypted. This feature provides an additional level of security to the default secure storage locations of the native SDKs.

By default the file encryption is disabled. If you use ScanbotSDK wrapper, you have to pass the following config parameters on SDK initialization:

new SBSDKConfiguration
Encryption = new SBSDKEncryption
Mode = EncryptionMode.AES256,
Password = "SomeSecretPa$$w0rdForFileEncryption"

You can also use the native bindings to enable encryption:

var initializer = new IO.Scanbot.Sdk.ScanbotSDKInitializer();
var processor = new AESEncryptedFileIOProcessor(
initializer.UseFileEncryption(true, processor);

By activating the storage encryption the native Scanbot SDKs will use the built-in AES 128 or AES 256 encryption. All generated image files (JPG, PNG) including the preview image files, as well as the exported PDF files will be encrypted in memory and stored as encrypted data files on the flash storage of the device.

The Scanbot SDK derives the AES key from the given password, an internal salt value, and the internal number of iterations using the PBKDF2 function.

When applying image operations like cropping, rotation or image filters, Scanbot SDK will decrypt the image file in memory, apply the changes, encrypt and store it again.

What do you think of this documentation?