IRONSOFTWAREHOME

How to Perform OCR on Android in .NET MAUI

Curtis Chau
Curtis Chau
Updated: August 2, 2026

.NET MAUI (Multi-platform App UI) is an evolution of the Xamarin.Forms framework, designed to create cross-platform apps for Android, iOS, macOS, and Windows using .NET. .NET MAUI aims to simplify the process of building native user interfaces that can run on multiple platforms.

The IronOcr.Android package brings OCR support to Android!

IronOCR Android Package

The IronOcr.Android package enables OCR features on Android devices via .NET cross-platform projects. The vanilla IronOCR package is not needed.

PM > Install-Package IronOcr.Android

C# NuGet Library for PDF

Install with NuGet

Install-Package IronOcr.Android

Create a .NET MAUI project

Open Visual Studio and click on "Create a new project". Search for MAUI, select .NET MAUI App and "Next".

Create .NET MAUI App project

Include the IronOCR.Android library

The library can be added in various ways. The easiest is perhaps by using NuGet.

  1. Inside Visual Studio, right-click on "Dependencies" and select "Manage NuGet Packages ...".
  2. Select the "Browse" tab and search for "IronOcr.Android".
  3. Select the "IronOcr.Android" package and click on "Install".

Download IronOcr.Android package

To prevent issues with other platforms, modify the csproj file to only include the package when targeting the Android platform. In order to do so:

  1. Right-click on the project and select "Edit Project File".

  2. Create a new ItemGroup element as such:

    <ItemGroup Condition="$(TargetFramework.Contains('android')) == true">
    </ItemGroup>
    XML
  3. Move the "IronOcr.Android" PackageReference inside the ItemGroup we just created.

The above steps will prevent the "IronOcr.Android" package from being used on e.g., iOS platforms (for that purpose, install IronOcr.iOS instead).

Edit "MainActivity.cs"

  • Open the "MainActivity.cs" file by navigating to Platforms -> Android.
  • Add the MainActivity method and invoke the Initialize method.
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
using IronOcr;

namespace MAUIIronOCRAndroidSample
{
    [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
    public class MainActivity : MauiAppCompatActivity
    {
        public MainActivity()
        {
            // Initialize IronTesseract for OCR purposes
            IronTesseract.Initialize(this);
        }
    }
}

Edit "MainPage.xaml"

Edit the XAML file to display a button and a label to show the OCR result. For example:

<?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"
             x:Class="MAUIIronOCRAndroidSample.MainPage">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Button
            Text="Import File"
            Clicked="ReadFileOnImport"
            Grid.Row="0"
            HorizontalOptions="Center"
            Margin="20, 20, 20, 10"/>

        <ScrollView
            Grid.Row="1"
            BackgroundColor="LightGray"
            Padding="10"
            Margin="10, 10, 10, 30">
            <Label x:Name="OutputText"/>
        </ScrollView>
    </Grid>

</ContentPage>
XML

Edit "MainPage.xaml.cs"

First, create an instance of the IronTesseract object. Ensure that IronTesseract is initialized once within the class, as demonstrated in the code below. Instantiating it within a method can be ineffective and may cause unexpected errors.

Next, use the FilePicker.PickAsync method to select a file, then open a reading stream from the FileResult. Create a new OcrInput object and load the image into it. Perform OCR on the image using the Tesseract instance and retrieve the text. Finally, display the resulting text in a label.

using IronOcr;
using Microsoft.Maui.Controls;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

namespace MAUIIronOCRAndroidSample
{
    public partial class MainPage : ContentPage
    {
        // Initialize IronTesseract once in a class
        private readonly IronTesseract ocrTesseract = new IronTesseract();

        public MainPage()
        {
            InitializeComponent();
            // Apply License key if required
            IronOcr.License.LicenseKey = "IRONOCR.MYLICENSE.KEY.1EF01";
        }

        private async void ReadFileOnImport(object sender, EventArgs e)
        {
            try
            {
                // Configure the file picker
                var options = new PickOptions
                {
                    PickerTitle = "Please select a file"
                };
                
                // Await user's file selection
                var result = await FilePicker.PickAsync(options);
                if (result != null)
                {
                    using var stream = await result.OpenReadAsync();
                    // Instantiate OcrInput
                    using var ocrInput = new OcrInput();
                    // Load image stream for OCR processing
                    ocrInput.LoadImage(stream);
                    // Perform OCR
                    var ocrResult = ocrTesseract.Read(ocrInput);
                    // Display extracted text
                    OutputText.Text = ocrResult.Text;
                }
            }
            catch (Exception ex)
            {
                // Log and handle exceptions
                Debug.WriteLine(ex);
            }
        }
    }
}
C#

Lastly, in the .csproj file, make sure that you are only building the project for Android. Since the package we added is only for Android, building the project for all platforms will fail.

Run the Project

This will show you how to run the project and perform OCR.

Execute .NET MAUI App project

Download .NET MAUI App Project

You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as a .NET MAUI App project.

Click here to download the project.

Using IronOcr.Android in Avalonia

Similar to MAUI, IronOcr.Android can be used in an Avalonia project with the same setup as described above.

If you want to perform OCR on iOS, navigate to the following article to learn more: "How to Perform OCR on iOS in .NET MAUI"

Frequently Asked Questions

What is the IronOCR Android package?

The IronOCR.Android package enables OCR features on Android devices using .NET cross-platform projects. It's specifically designed to integrate with the .NET MAUI framework for Android development.

How do I install the IronOCR.Android package using NuGet?

Open Visual Studio, right-click on 'Dependencies' and select 'Manage NuGet Packages'. Under the 'Browse' tab, search for 'IronOcr.Android', select the package, and click 'Install'.

Can I use IronOCR.Android with other platforms?

IronOCR.Android is tailored for Android platforms. For cross-platform support, such as iOS, you should use the platform-specific versions like IronOcr.iOS.

How do I configure a .NET MAUI project for IronOCR?

Start by creating a .NET MAUI App project in Visual Studio. Include the IronOCR.Android library via NuGet and modify the .csproj file to target the Android platform specifically.

What steps are required to perform OCR in a .NET MAUI application?

To perform OCR, initialize IronTesseract in your 'MainActivity.cs', configure your XAML files for UI, and handle file inputs and OCR processing in 'MainPage.xaml.cs'.

How does IronOCR handle file selection and OCR in C#?

IronOCR uses the FilePicker.PickAsync method for file selection in .NET MAUI apps. After a user selects a file, IronTesseract processes the image to perform OCR and extracts text data.

What is required in the project file to ensure it targets only Android?

In the .csproj file, create an ItemGroup with a condition to target Android using `` to ensure only the 'IronOcr.Android' package is used.

How can you download a complete sample project using IronOCR?

You can download the complete .NET MAUI App project with the IronOCR.Android setup from the provided guide link, which includes a zipped file for use in Visual Studio.

Is it possible to use IronOCR in an Avalonia project?

Yes, IronOCR.Android can be used in an Avalonia project with comparable setup steps as outlined for .NET MAUI applications.

How do you initialize IronTesseract in a MAUI project?

Within your 'MainActivity', initialize IronTesseract by calling `IronTesseract.Initialize(this);` to prepare it for OCR operations in your Android app.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required