Persian OCR in C# and .NET
Other versions of this document:
IronOCR is a C# software component allowing .NET coders to read text from images and PDF documents in 126 languages, including Persian.
It is an advanced fork of Tesseract, built exclusively for .NET developers and regularly outperforms other Tesseract engines for both speed and accuracy.
Contents of IronOcr.Languages.Persian
This package contains 46 OCR languages for .NET:
- Persian
- PersianBest
- PersianFast
Download
Persian Language Pack [فارسی]
Installation
The first thing we have to do is install our Persian OCR package to your .NET project.
PM> Install-Package IronOCR.Languages.Persian
Code Example
This C# code example reads Persian text from an image or PDF document.
// Install IronOcr.Languages.Persian package using NuGet Package Manager
// PM> Install-Package IronOcr.Languages.Persian
using IronOcr;
class Program
{
static void Main()
{
// Create a new instance of IronTesseract
var Ocr = new IronTesseract();
// Set the language to Persian
Ocr.Language = OcrLanguage.Persian;
// Load input image or PDF file
using (var Input = new OcrInput(@"images\Persian.png"))
{
// Perform OCR to read text from the image
var Result = Ocr.Read(Input);
// Extract the recognized text
var AllText = Result.Text;
// Display the extracted text
Console.WriteLine(AllText);
}
}
}
// Install IronOcr.Languages.Persian package using NuGet Package Manager
// PM> Install-Package IronOcr.Languages.Persian
using IronOcr;
class Program
{
static void Main()
{
// Create a new instance of IronTesseract
var Ocr = new IronTesseract();
// Set the language to Persian
Ocr.Language = OcrLanguage.Persian;
// Load input image or PDF file
using (var Input = new OcrInput(@"images\Persian.png"))
{
// Perform OCR to read text from the image
var Result = Ocr.Read(Input);
// Extract the recognized text
var AllText = Result.Text;
// Display the extracted text
Console.WriteLine(AllText);
}
}
}
' Install IronOcr.Languages.Persian package using NuGet Package Manager
' PM> Install-Package IronOcr.Languages.Persian
Imports IronOcr
Friend Class Program
Shared Sub Main()
' Create a new instance of IronTesseract
Dim Ocr = New IronTesseract()
' Set the language to Persian
Ocr.Language = OcrLanguage.Persian
' Load input image or PDF file
Using Input = New OcrInput("images\Persian.png")
' Perform OCR to read text from the image
Dim Result = Ocr.Read(Input)
' Extract the recognized text
Dim AllText = Result.Text
' Display the extracted text
Console.WriteLine(AllText)
End Using
End Sub
End Class
The above code example demonstrates how to utilize the IronOCR library to perform OCR on a Persian image. It's essential to have the Persian language pack installed, and the path to the image should be specified correctly. The OCR operation is performed within a using
statement to ensure proper disposal of resources.