How to Read Specialized Documents with C# and IronOCR
Accurately reading specific documents such as standard text documents, license plates, passports, and photos with a general singular method is very hard. These challenges stem from the diverse formats, layouts, and content of each document type, as well as variations in image quality, distortion, and specialized content. Additionally, achieving contextual understanding and balancing performance and efficiency becomes more complex with a broader scope of document types.
IronOCR introduces specific methods for performing OCR on particular documents such as standard text documents, license plates, passports, and photos to achieve optimal accuracy and performance.
Quickstart: Read a Passport in One LineUse IronOCR's ReadPassport extension to extract all key passport details with minimal setup. With just one line of code - assuming you've installed IronOCR and AdvancedScan - you'll get structured result data like names, passport number, country, and more, fast and effortlessly.
-
1Install IronOCR with NuGet Package Manager
-
2Copy and run this code snippet.
var result = new IronTesseract().ReadPassport(new OcrInput().LoadImage("passport.jpg"));C# -
3Deploy to test on your live environment
Start using IronOCR in your project today with a free trial
Minimal Workflow (5 steps)
- Download a C# library to read license plates, passports, and photos
- Prepare the image and PDF document for OCR
- Set the
ReadLicensePlatemethod to read a license plate - Set the
ReadPassportmethod to retrieve information from a passport - Leverage the
ReadPhotoandReadScreenShotmethods to read images that contain hard-to-read text
About The Package
The methods ReadLicensePlate, ReadPassport, ReadPhoto, and ReadScreenShot are extension methods to the base IronOCR package and require the IronOcr.Extensions.AdvancedScan package to be installed.
The methods work with OCR engine configurations such as blacklist and whitelist. Multiple languages, including Chinese, Japanese, Korean, and LatinAlphabet, are supported in all methods except for the ReadPassport method. Please note that each language requires an additional language package, IronOcr.Languages.
Using advanced scan on .NET Framework requires the project to run on x64 architecture. Navigate to the project configuration and uncheck the "Prefer 32-bit" option to achieve this. Learn more in the following troubleshooting guide: "Advanced Scan on .NET Framework."
Read Document Example
The ReadDocument method is a robust document reading method that specializes in scanned documents or photos of paper documents containing a lot of text. The PageSegmentationMode configuration is very important in reading text documents with different layouts.
For example, the SingleBlock and SparseText types could retrieve much information from table layout. This is because SingleBlock assumes that the text stays as a block, whereas SparseText assumes that the text is scattered throughout the document.
using IronOcr;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
// Configure OCR engine
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
using var input = new OcrInput();
input.LoadPdf("Five.pdf");
// Perform OCR
OcrResult result = ocr.ReadDocument(input);
Console.WriteLine(result.Text);Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
' Configure OCR engine
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock
Dim input = New OcrInput()
input.LoadPdf("Five.pdf")
' Perform OCR
Dim result As OcrResult = ocr.ReadDocument(input)
Console.WriteLine(result.Text)The methods below are extension methods to the base IronOCR package and require the IronOcr.Extensions.AdvancedScan package to be installed.
Read License Plate Example
The ReadLicensePlate method is optimized for reading license plates from photos. The special information returned from this method is the Licenseplate property, which contains the information of the license plate location in the provided document.
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("LicensePlate.jpeg");
// Perform OCR
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate coordinates
Rectangle rectangle = result.Licenseplate;
// Retrieve license plate value
string output = result.Text;Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("LicensePlate.jpeg")
' Perform OCR
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate coordinates
Dim rectangle As Rectangle = result.Licenseplate
' Retrieve license plate value
Dim output As String = result.TextRead Passport Example
The ReadPassport method is optimized for reading and extracts passport information from passport photos by scanning the machine-readable zone (MRZ) contents. An MRZ is a specially defined zone in official documents such as passports, ID cards, and visas. The MRZ typically contains essential personal information, such as the holder's name, date of birth, nationality, and document number. Currently, this method only supports the English language.
using IronOcr;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.LoadImage("Passport.jpg");
// Perform OCR
OcrPassportResult result = ocr.ReadPassport(inputPassport);
// Output passport information
Console.WriteLine(result.PassportInfo.GivenNames);
Console.WriteLine(result.PassportInfo.Country);
Console.WriteLine(result.PassportInfo.PassportNumber);
Console.WriteLine(result.PassportInfo.Surname);
Console.WriteLine(result.PassportInfo.DateOfBirth);
Console.WriteLine(result.PassportInfo.DateOfExpiry);Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPassport = New OcrInput()
inputPassport.LoadImage("Passport.jpg")
' Perform OCR
Dim result As OcrPassportResult = ocr.ReadPassport(inputPassport)
' Output passport information
Console.WriteLine(result.PassportInfo.GivenNames)
Console.WriteLine(result.PassportInfo.Country)
Console.WriteLine(result.PassportInfo.PassportNumber)
Console.WriteLine(result.PassportInfo.Surname)
Console.WriteLine(result.PassportInfo.DateOfBirth)
Console.WriteLine(result.PassportInfo.DateOfExpiry)Result

Please make sure that the document only contains the passport image. Any header and footer text could confuse the method and result in an unexpected output.
Read Photo Example
The ReadPhoto method is optimized for reading images that contain hard-to-read text. This method returns the TextRegions property, which contains useful information about the detected text, such as Region, TextInRegion, and PageNumber.
using IronOcr;
using IronSoftware.Drawing;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPhoto = new OcrInput();
inputPhoto.LoadImageFrame("photo.tif", 2);
// Perform OCR
OcrPhotoResult result = ocr.ReadPhoto(inputPhoto);
// index number refer to region order in the page
int number = result.TextRegions[0].PageNumber;
string textinregion = result.TextRegions[0].TextInRegion;
Rectangle region = result.TextRegions[0].Region;Imports IronOcr
Imports IronSoftware.Drawing
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPhoto = New OcrInput()
inputPhoto.LoadImageFrame("photo.tif", 2)
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadPhoto(inputPhoto)
' index number refer to region order in the page
Dim number As Integer = result.TextRegions(0).PageNumber
Dim textinregion As String = result.TextRegions(0).TextInRegion
Dim region As Rectangle = result.TextRegions(0).RegionRead Screenshot Example
The ReadScreenShot method is optimized for reading screenshots that contain hard-to-read text. Similar to the ReadPhoto method, it also returns the TextRegions property.
using IronOcr;
using System;
using System.Linq;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputScreenshot = new OcrInput();
inputScreenshot.LoadImage("screenshot.png");
// Perform OCR
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);
// Output screenshoot information
Console.WriteLine(result.Text);
Console.WriteLine(result.TextRegions.First().Region.X);
Console.WriteLine(result.TextRegions.Last().Region.Width);
Console.WriteLine(result.Confidence);Imports IronOcr
Imports System
Imports System.Linq
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputScreenshot = New OcrInput()
inputScreenshot.LoadImage("screenshot.png")
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadScreenShot(inputScreenshot)
' Output screenshoot information
Console.WriteLine(result.Text)
Console.WriteLine(result.TextRegions.First().Region.X)
Console.WriteLine(result.TextRegions.Last().Region.Width)
Console.WriteLine(result.Confidence)Frequently Asked Questions
What types of documents can be read using IronOCR?
IronOCR can read various document types, including standard text documents, license plates, passports, and photos. It offers specialized methods such as `ReadPassport`, `ReadLicensePlate`, `ReadPhoto`, and `ReadScreenShot` to optimize accuracy and performance for each document type.
How does IronOCR enhance reading specific document types?
IronOCR enhances reading specific document types by using tailored methods that consider diverse formats, layouts, and content types. For instance, there are dedicated functions for reading license plates and passports, which improve accuracy by focusing on relevant sections, such as machine-readable zones in passports.
Can IronOCR extract MRZ information from passports?
Yes, the `ReadPassport` method in IronOCR is specifically designed to extract information from the machine-readable zone of passport photos, providing details such as the holder's name, nationality, and passport number.
Is additional configuration required for using IronOCR on .NET Framework?
Yes, when using advanced scan features with IronOCR on .NET Framework, it's important to run the project on x64 architecture by unchecking 'Prefer 32-bit' in the project configuration.
Does IronOCR support multiple languages for OCR processes?
IronOCR supports multiple languages for OCR processes, including Chinese, Japanese, Korean, and LatinAlphabet, through additional language packages. However, the `ReadPassport` method currently supports only English.
What is the `ReadPhoto` method used for in IronOCR?
The `ReadPhoto` method in IronOCR is optimized for reading images that contain hard-to-read text and provides detailed information such as text regions and page numbers for better text extraction results.
How does IronOCR handle text extraction from screenshots?
IronOCR uses the `ReadScreenShot` method to extract text from screenshots. This method is optimized to detect and provide information about text regions, allowing for effective text extraction from screen captures.
What is the purpose of the `ReadLicensePlate` method in IronOCR?
The `ReadLicensePlate` method is optimized for reading license plates from photos, allowing for extraction of license plate coordinates and values, which can be crucial for applications like traffic monitoring and vehicle recognition systems.
What precautions should be taken when using the `ReadPassport` method?
When using the `ReadPassport` method, ensure that the image only contains the passport photo to avoid confusion and unexpected output. Any additional text like headers and footers should be excluded.
How can IronOCR be installed to perform document reading in C#?
IronOCR can be installed via the NuGet package manager. Ensure that both IronOCR and IronOcr.Extensions.AdvancedScan are installed to utilize methods for reading specialized document types like license plates and passports.

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.