Skip to main content

Building an interface for scanning documents with the Custom UI Components

The Document Scanner view exposes a configurable camera view that allows you to detect documents in real time.

Required: Permission validation

Custom UI Components do not automatically validate camera access permissions. It's up to developers to request and secure these permissions within their applications. Before integrating camera functionalities, ensure that your app has obtained the necessary permissions to provide users with a seamless experience.

Document Scanner Component

Embed the component in your layout and use the OnSnappedDocumentImageResult callback to handle the document result. The OnUpdateDetectionStatus callback provides the detection status of the document being scanned.

Customize the UI and behavior of DocumentScannerView by using the component's properties. Each property is optional, and falls back to its default value if not specified.

More on the available properties can be found in the API documentation.

You can utilize the DocumentScannerView class from xmlns:classicComponent="clr-namespace:ScanbotSDK.MAUI.Document.ClassicComponent;assembly=DocumentSDK.MAUI" to integrate document scanning functionalities into your application seamlessly.

This component encapsulates the document scanning feature within a single UI component.

Custom UI layout
loading...
Custom UI EventHandlers
loading...
Custom UI EventHandlers Implementation
loading...

Frequent use cases

note

The following information only covers the MAUI Custom UI Component, i.e., the DocumentScannerView.

Camera view visibility

The Scanbot SDK provides a convenient way to control the visibility of the DocumentScannerView, including automatic handling of the camera resource. This is useful when the DocumentScannerView is expected to be hidden completely.

Use the IsVisible property to toggle the visibility of the scanner view. When IsVisible is set to false, scanning stops, the camera preview is turned off, and the DocumentScannerView becomes hidden.

IsVisible Property
documentScannerView.IsVisible = false; // Hides the view and stops scanning.
documentScannerView.IsVisible = true; // Shows the view and resumes scanning.
info

You may also use this property if you need to navigate forward from the DocumentScannerView page to another page and plan to return to it later.

Camera view start/stop

The DocumentScannerView can freeze/unfreeze the camera preview. This is useful for pausing the camera preview on the last scanned frame before a freeze operation.

Use the IsCameraFrozen property to freeze/unfreeze the camera preview of the DocumentScannerView. When IsCameraFrozen is set to true, scanning stops and the camera preview is paused on the last scanned frame.

IsCameraFrozen Property
documentScannerView.IsCameraFrozen = false; // Unfreeze the camera preview and resumes the document scanning.
documentScannerView.IsCameraFrozen = true; // Freezes the camera preview and stops the document scanning.
info

You may use this property if you need to navigate forward from the DocumentScannerView page to another page and plan to return to it later. Or if you wish to show any pop-up over the camera preview.

The DocumentScannerView is a .NET MAUI implementation (wrapper) built using a ViewHandler, which natively integrates the iOS SBSDKDocumentScannerViewController and Android DocumentScannerView.

The .NET MAUI ViewHandler has its own lifecycle methods. For more details, refer to the official Microsoft documentation.

When navigating between pages, it's important to properly handle camera resources and view deallocation to avoid potential memory leaks.

DisconnectHandler

The DisconnectHandler() method is responsible for removing and deallocating all native classes and camera resources used by the DocumentScannerView (i.e., the common ViewHandler implementation).

Since .NET 9, this method is invoked automatically by the MAUI framework.

The DisconnectHandler() is invoked automatically when navigating back (e.g., using Navigation.Pop...Async();) from the DocumentScannerView's page, that disposes and deallocates all related resources.

If you are navigating forward (e.g., using Navigation.PushAsync();) from the DocumentScannerView's page, it is recommended to temporarily disable the camera instead of fully disconnecting it. You can do this by setting either: IsCameraFrozen = true, or IsVisible = false.

When you navigate back to the DocumentScannerView page, simply set: IsCameraFrozen = false, or IsVisible = true, to resume scanning and camera preview functionality.

note

If you need to invoke DisconnectHandler() regardless of the navigation direction, make sure to reinitialize the DocumentScannerView before accessing it again.

Pause/resume

During the document scanning flow, there may be scenarios where you need to pause the camera to show a popup, or when you navigate to the next page from the DocumentScannerView page with the intention to return later.

In such cases, refer to the "Camera view visibility" or the "Camera view start/stop" sections above.

For a fully functional example, refer to our .NET and MAUI example apps on GitHub.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license