How to Perform OCR on iOS in .NET MAUI
.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. MAUI aims to simplify the process of building native user interfaces that can run on multiple platforms.
The IronOcr.iOS package brings OCR support to iOS!
How to use IronOCR on iOS in .NET MAUI
- Download the C# library to perform OCR on iOS
- Create a .NET MAUI App project
- Edit the XAML file to display an activation button and output text
- Edit the corresponding C# file to perform the OCR
- Download the sample project for a quick start
IronOCR iOS Package
The IronOcr.iOS package enables OCR features on iOS devices via .NET cross-platform projects. The vanilla IronOCR package is not needed.
Install with NuGet
Install-Package IronOcr.iOS
Create a .NET MAUI Project
Under the Multiplatform section, select .NET MAUI App and continue.

Include the IronOCR.iOS Library
The library can be added in various ways. The easiest is perhaps by using NuGet.
- Inside Visual Studio, right-click on "Dependencies > Nuget" and select "Manage NuGet Packages ...".
- Select the "Browse" tab and search for "IronOcr.iOS".
- Select the "IronOcr.iOS" package and click on "Add Package".

To prevent issues with other platforms, modify the csproj file to only include the package when targeting the iOS platform. In order to do so:
-
Right-click on the *.csproj file for your project and select "Edit Project File".
-
Create a new
ItemGroupelement as such:<ItemGroup Condition="$(TargetFramework.Contains('ios')) == true"> <PackageReference Include="IronOcr.iOS" Version="YOUR_PACKAGE_VERSION" /> </ItemGroup>XML -
Move the "IronOcr.iOS" PackageReference inside the
ItemGroupwe just created.
The above steps will prevent the "IronOcr.iOS" package from being used on, e.g., Android platforms (for that purpose, install IronOcr.Android instead).
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="MAUIIronOCRiOSSample.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>
Edit "MainPage.xaml.cs"
Start by instantiating the IronTesseract object. Make sure to initialize IronTesseract once in a class, as shown in the code below. Instantiating it directly in a method is not effective and could lead to unexpected errors. Then, use the FilePicker.PickAsync method to select a file. From the FileResult, open a stream for reading. Create a new OcrInput object and use this object to load the image. Use the Tesseract instance to perform OCR on the image and return the text. Finally, display the resulting text in a label.
The current implementation is limited to image files only. The package does not work with PDF documents yet. With this in mind, any configuration related to PDF documents should remain deactivated.
using System;
using IronOcr;
using Microsoft.Maui.Controls;
namespace MAUIIronOCRiOSSample;
public partial class MainPage : ContentPage
{
// Initialize IronTesseract once in a class
private IronTesseract ocrTesseract = new IronTesseract();
public MainPage()
{
InitializeComponent();
// Apply license key
IronOcr.License.LicenseKey = "IRONOCR-MYLICENSE-KEY-1EF01";
}
private async void ReadFileOnImport(object sender, EventArgs e)
{
try
{
var options = new PickOptions
{
PickerTitle = "Please select a file"
};
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
ocrInput.LoadImage(stream);
// Perform OCR
var ocrResult = ocrTesseract.Read(ocrInput);
OutputText.Text = ocrResult.Text;
}
}
catch (Exception ex)
{
// Handle exceptions
System.Diagnostics.Debug.WriteLine(ex);
}
}
}Imports System
Imports IronOcr
Imports Microsoft.Maui.Controls
Namespace MAUIIronOCRiOSSample
Partial Public Class MainPage
Inherits ContentPage
' Initialize IronTesseract once in a class
Private ocrTesseract As New IronTesseract()
Public Sub New()
InitializeComponent()
' Apply license key
IronOcr.License.LicenseKey = "IRONOCR-MYLICENSE-KEY-1EF01"
End Sub
Private Async Sub ReadFileOnImport(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim options = New PickOptions With {.PickerTitle = "Please select a file"}
Dim result = Await FilePicker.PickAsync(options)
If result IsNot Nothing Then
Dim stream = Await result.OpenReadAsync()
' Instantiate OcrInput
Dim ocrInput As New OcrInput()
' Load image stream
ocrInput.LoadImage(stream)
' Perform OCR
Dim ocrResult = ocrTesseract.Read(ocrInput)
OutputText.Text = ocrResult.Text
End If
Catch ex As Exception
' Handle exceptions
System.Diagnostics.Debug.WriteLine(ex)
End Try
End Sub
End Class
End NamespaceLastly, switch the build target to iOS Simulator and run the project.
Run the Project
This will show you how to run the project and perform OCR.
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.iOS in Avalonia
Setting up IronOcr.iOS in Avalonia is similar to MAUI, with one crucial difference: in addition to the latest .NET SDK version, you also need .NET SDK 8.0.101 installed to run IronOcr.iOS successfully. Afterward, IronOcr.iOS can be used in an Avalonia project with the same setup as described above.
If you want to perform OCR on Android, navigate to the following article to learn more: "How to Perform OCR on Android in .NET MAUI"
Frequently Asked Questions
What is IronOCR used for on iOS in .NET MAUI?
IronOCR is used to perform Optical Character Recognition (OCR) on iOS devices within .NET MAUI applications. It allows developers to extract text from images seamlessly.
How do I install the IronOCR package for iOS?
To install the IronOCR package for iOS, use the NuGet Package Manager in Visual Studio. Search for 'IronOcr.iOS' in the 'Browse' tab and add it to your project.
Can I use IronOCR for PDF document processing on iOS?
As of now, IronOCR for iOS is limited to processing image files. It does not support PDF document processing.
What are the basic steps to implement OCR using IronOCR on iOS?
First, set up a .NET MAUI project, then download and install IronOcr.iOS via NuGet. Configure your project files properly, instantiate IronTesseract, and use it to process images for text extraction.
Do I need to include IronOCR in platform-specific ways in a MAUI project?
Yes, to prevent conflicts, modify your project file to include IronOCR only when targeting iOS. This ensures that the package is not mistakenly used on other platforms like Android.
Is there a sample project available for IronOCR on iOS?
Yes, a sample .NET MAUI App project for IronOCR on iOS is available for download, providing a ready-to-run example of how to implement OCR functionality.
What is required for using IronOCR iOS in Avalonia?
In addition to the usual setup, you'll need .NET SDK version 8.0.101 installed alongside the latest .NET SDK to run IronOCR iOS in an Avalonia project.
How do I ensure IronOCR is not included in non-iOS builds?
Edit the csproj file to create a conditional ItemGroup that includes the IronOCR package reference only if the target framework is iOS.
How does the Image input and OCR process work in IronOCR for iOS?
In IronOCR, an image stream is loaded into an OcrInput object. This object is then processed by an IronTesseract instance to extract text, which can be displayed in your application's UI.

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.