Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
With the rise of mobile technology, document-scanning apps such as Scanbot SDK, and Native SDKs have become indispensable tools for both individuals and businesses. In this tutorial, we'll explore how to create a document scanner app using the latest version of .NET Multi-platform App UI (MAUI) and IronOCR, a powerful OCR (Optical Character Recognition) library for .NET. .NET MAUI simplifies the creation of cross-platform mobile apps, ensuring seamless deployment on devices such as Android. By the end of this guide, you'll be able to develop your own document scanner SDK app that can extract text from images and scanned files with ease.
IronOCR is a cutting-edge Optical Character Recognition (OCR) software developed by Iron Software, LLC, designed to accurately and efficiently convert images and scanned documents into editable text. OCR technology has revolutionized how businesses handle document processing, making it easier to extract valuable information from various sources such as scanned documents, PDFs, and images.
IronOCR stands out among OCR solutions due to its advanced features, robust performance, and ease of integration. Whether you're a developer looking to incorporate OCR features into your applications or a business seeking to streamline document management processes, IronOCR offers a comprehensive solution.
Let's start by designing the layout of our MainPage.xaml. We'll create a simple layout with an image control to display the captured photo, a Capture button to take photos, and a Label to display the extracted text.
Here's the XAML code for MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
x:Class="DocumentScanner.MainPage">
<ScrollView>
<VerticalStackLayout Padding="30,0" Spacing="25">
<Image Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
<Label Text="Welcome to .NET MAUI Document Scanner SDK"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label Text="Using IronOCR"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to .NET MAUI Document Scanner SDK" />
<!-- Camera preview -->
<Image x:Name="cameraPreview" />
<!-- Capture button -->
<Button Text="Capture" Clicked="OnCaptureClicked" />
<!-- Text display area -->
<Label x:Name="textLabel" Text="Recognized Text:"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
x:Class="DocumentScanner.MainPage">
<ScrollView>
<VerticalStackLayout Padding="30,0" Spacing="25">
<Image Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
<Label Text="Welcome to .NET MAUI Document Scanner SDK"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label Text="Using IronOCR"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to .NET MAUI Document Scanner SDK" />
<!-- Camera preview -->
<Image x:Name="cameraPreview" />
<!-- Capture button -->
<Button Text="Capture" Clicked="OnCaptureClicked" />
<!-- Text display area -->
<Label x:Name="textLabel" Text="Recognized Text:"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
In this layout:
To integrate text extraction functionality into our .NET MAUI Document Scanning app, we will follow these steps:
Here's the corresponding code snippet implementing these steps:
using IronOcr;
namespace DocumentScanner
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void OnCaptureClicked(object sender, EventArgs e)
{
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
try
{
// Request camera permissions
var status = await Permissions.RequestAsync<Permissions.Camera>();
if (status == PermissionStatus.Granted)
{
// Take photo
var photo = await MediaPicker.CapturePhotoAsync();
if (photo != null)
{
// Display captured photo in Image
cameraPreview.Source = ImageSource.FromStream(() => photo.OpenReadAsync().Result);
using (var stream = await photo.OpenReadAsync())
{
// Use a stream from the captured photo for OCR
var ocr = new IronTesseract();
using var ocrInput = new OcrInput();
ocrInput.LoadImage(stream);
var ocrResult = ocr.Read(ocrInput);
if (string.IsNullOrEmpty(ocrResult.Text))
{
await DisplayAlert("Error", "No Text Detected!", "OK");
}
else
{
await DisplayAlert("Text Detected!", ocrResult.Text, "OK");
// Display extracted text
textLabel.Text = ocrResult.Text;
}
}
}
}
else
{
// Camera permission denied
await DisplayAlert("Permission Denied", "Camera permission is required to capture photos.", "OK");
}
}
catch (Exception ex)
{
// Handle exception
await DisplayAlert("Error", ex.Message, "OK");
}
}
}
}
using IronOcr;
namespace DocumentScanner
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void OnCaptureClicked(object sender, EventArgs e)
{
License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
try
{
// Request camera permissions
var status = await Permissions.RequestAsync<Permissions.Camera>();
if (status == PermissionStatus.Granted)
{
// Take photo
var photo = await MediaPicker.CapturePhotoAsync();
if (photo != null)
{
// Display captured photo in Image
cameraPreview.Source = ImageSource.FromStream(() => photo.OpenReadAsync().Result);
using (var stream = await photo.OpenReadAsync())
{
// Use a stream from the captured photo for OCR
var ocr = new IronTesseract();
using var ocrInput = new OcrInput();
ocrInput.LoadImage(stream);
var ocrResult = ocr.Read(ocrInput);
if (string.IsNullOrEmpty(ocrResult.Text))
{
await DisplayAlert("Error", "No Text Detected!", "OK");
}
else
{
await DisplayAlert("Text Detected!", ocrResult.Text, "OK");
// Display extracted text
textLabel.Text = ocrResult.Text;
}
}
}
}
else
{
// Camera permission denied
await DisplayAlert("Permission Denied", "Camera permission is required to capture photos.", "OK");
}
}
catch (Exception ex)
{
// Handle exception
await DisplayAlert("Error", ex.Message, "OK");
}
}
}
}
Imports IronOcr
Namespace DocumentScanner
Partial Public Class MainPage
Inherits ContentPage
Public Sub New()
InitializeComponent()
End Sub
Private Async Sub OnCaptureClicked(ByVal sender As Object, ByVal e As EventArgs)
License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
Try
' Request camera permissions
Dim status = Await Permissions.RequestAsync(Of Permissions.Camera)()
If status = PermissionStatus.Granted Then
' Take photo
Dim photo = Await MediaPicker.CapturePhotoAsync()
If photo IsNot Nothing Then
' Display captured photo in Image
cameraPreview.Source = ImageSource.FromStream(Function() photo.OpenReadAsync().Result)
Using stream = Await photo.OpenReadAsync()
' Use a stream from the captured photo for OCR
Dim ocr = New IronTesseract()
Dim ocrInput As New OcrInput()
ocrInput.LoadImage(stream)
Dim ocrResult = ocr.Read(ocrInput)
If String.IsNullOrEmpty(ocrResult.Text) Then
Await DisplayAlert("Error", "No Text Detected!", "OK")
Else
Await DisplayAlert("Text Detected!", ocrResult.Text, "OK")
' Display extracted text
textLabel.Text = ocrResult.Text
End If
End Using
End If
Else
' Camera permission denied
Await DisplayAlert("Permission Denied", "Camera permission is required to capture photos.", "OK")
End If
Catch ex As Exception
' Handle exception
Await DisplayAlert("Error", ex.Message, "OK")
End Try
End Sub
End Class
End Namespace
Let's break down the code step by step:
"YOUR-LICENSE-KEY-HERE"
with your actual license key.For further exploration of IronOCR and additional code examples, visit this code examples page.
By following this tutorial, you've learned how to use the IronOCR document scanner SDK within .NET MAUI. Document scanning apps have numerous practical applications, from digitizing paper documents to extracting stored information from receipts and invoices. Using the powerful capabilities of IronOCR and the flexibility of .NET MAUI, you can build feature-rich document scanner apps that cater to various use cases. Experiment with different functionalities, explore additional libraries, and continue honing your skills to create even more impressive apps.
For more detailed information on IronOCR capabilities, please visit this documentation page.
IronOCR provides a free trial to test its complete functionality in commercial mode. Its perpetual lite license starts from $749. Download the library from the download page and give it a try.
The tutorial teaches how to create a document scanner app using .NET MAUI and IronOCR, a C# OCR library.
IronOCR is an Optical Character Recognition (OCR) software developed by Iron Software, LLC, that converts images and scanned documents into editable text.
You install IronOCR by managing NuGet Packages in Visual Studio, searching for 'IronOCR', and adding it to your project.
Basic knowledge of C# programming, Visual Studio 2022 with .NET MAUI workload, and IronOCR package installed via NuGet Package Manager are required.
IronOCR is used to perform OCR on images captured within the app, extracting text from them.
Yes, IronOCR supports text recognition in over 127 languages.
Key features include high accuracy, multi-language support, image preprocessing, support for various file formats, customization options, fast performance, integration with .NET applications, and document classification.
.NET MAUI enables developers to create cross-platform mobile apps with a single codebase, ensuring seamless deployment on Android, iOS, and Windows devices.
Steps include capturing an image using the camera API, passing the image to IronOCR for text extraction, and displaying the extracted text in the app's UI.
IronOCR supports a wide range of file formats, including TIFF, JPEG, PNG, and PDF.