using NuGet Package Manager 將 IronOCR NuGet 方案包安裝到您的 Visual Studio 解決方案中。
using IronOcr;using System;var ocr = new IronTesseract();using var input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames(@"img\example.tiff", pageindices);input.DeNoise(); //fixes digital noiseinput.Deskew(); //fixes rotation and perspective// there are dozens more filters, but most users wont need themOcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
using System;
var ocr = new IronTesseract();
using var input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\example.tiff", pageindices);
input.DeNoise(); //fixes digital noise
input.Deskew(); //fixes rotation and perspective
// there are dozens more filters, but most users wont need them
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrImportsSystemPrivate ocr = New IronTesseract()Private input = New OcrInput()Private pageindices = New Integer() { 1, 2 }input.LoadImageFrames("img\example.tiff", pageindices)input.DeNoise() 'fixes digital noiseinput.Deskew() 'fixes rotation and perspective' there are dozens more filters, but most users wont need themDim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
Private input = New OcrInput()
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\example.tiff", pageindices)
input.DeNoise() 'fixes digital noise
input.Deskew() 'fixes rotation and perspective
' there are dozens more filters, but most users wont need them
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
這段程式碼展示了 IronOCR 簡化的 API 的強大功能。 IronTesseract 類提供了單個托管的 Tesseract 5 包裝,消除了複雜的 C++ 互操作的需要。OcrInput 類支持載入多個圖片格式和頁面,而可選的預處理方法 (DeNoise() 和 Deskew()) 可以顯著提高真實世界文件的準確性。
除了基本的文字提取外,OcrResult 物件提供豐富的結構化資料,包括字詞級信心分數、字元位置和文件結構 - 這使得 可搜索 PDF 建立 和 精確文字位置跟踪 等高級功能得以實現。
Tesseract 和 IronOCR 的安裝有何主要不同?
使用 .NET 的 Tesseract 引擎進行 OCR
在 C# 中傳統的 Tesseract 整合需要管理 C++ 庫,這造成了一些挑戰。
開發者必須處理平台特定的二進制文件,確保安裝 Visual C++ 運行時,並處理 32/64 位相容性問題。 設置通常要求手動編譯 Tesseract 和 Leptonica 庫,特別是對於最新的 Tesseract 5 版本,這些版本不是為 Windows 編譯而設計的。
using IronOcr;using System;// Create an instance of the IronTesseract class for OCR processingvar ocr = new IronTesseract();// Create an OcrInput object to load and preprocess imagesusing var input = new OcrInput();// Specify which pages to extract from multi-page documentsvar pageIndices = new int[] { 1, 2 };// Load specific frames from a TIFF file// IronOCR automatically detects and handles various image formatsinput.LoadImageFrames(@"img\example.tiff", pageIndices);// Apply automatic image enhancement filters// These filters dramatically improve accuracy on imperfect scansinput.DeNoise(); // Removes digital artifacts and specklesinput.Deskew(); // Corrects rotation up to 15 degrees// Perform OCR with enhanced accuracy algorithmsOcrResult result = ocr.Read(input);// Access the extracted text with confidence metricsConsole.WriteLine(result.Text);// Additional accuracy features available:// - result.Confidence: Overall accuracy percentage// - result.Pages[0].Words: Word-level confidence scores// - result.Blocks: Structured document layout analysis
using IronOcr;
using System;
// Create an instance of the IronTesseract class for OCR processing
var ocr = new IronTesseract();
// Create an OcrInput object to load and preprocess images
using var input = new OcrInput();
// Specify which pages to extract from multi-page documents
var pageIndices = new int[] { 1, 2 };
// Load specific frames from a TIFF file
// IronOCR automatically detects and handles various image formats
input.LoadImageFrames(@"img\example.tiff", pageIndices);
// Apply automatic image enhancement filters
// These filters dramatically improve accuracy on imperfect scans
input.DeNoise(); // Removes digital artifacts and speckles
input.Deskew(); // Corrects rotation up to 15 degrees
// Perform OCR with enhanced accuracy algorithms
OcrResult result = ocr.Read(input);
// Access the extracted text with confidence metrics
Console.WriteLine(result.Text);
// Additional accuracy features available:
// - result.Confidence: Overall accuracy percentage
// - result.Pages[0].Words: Word-level confidence scores
// - result.Blocks: Structured document layout analysis
ImportsIronOcrImportsSystem' Create an instance of the IronTesseract class for OCR processingPrivate ocr = New IronTesseract()' Create an OcrInput object to load and preprocess imagesPrivate input = New OcrInput()' Specify which pages to extract from multi-page documentsPrivate pageIndices = New Integer() { 1, 2 }' Load specific frames from a TIFF file' IronOCR automatically detects and handles various image formatsinput.LoadImageFrames("img\example.tiff", pageIndices)' Apply automatic image enhancement filters' These filters dramatically improve accuracy on imperfect scansinput.DeNoise() ' Removes digital artifacts and specklesinput.Deskew() ' Corrects rotation up to 15 degrees' Perform OCR with enhanced accuracy algorithmsDim result AsOcrResult = ocr.Read(input)' Access the extracted text with confidence metricsConsole.WriteLine(result.Text)' Additional accuracy features available:' - result.Confidence: Overall accuracy percentage' - result.Pages[0].Words: Word-level confidence scores' - result.Blocks: Structured document layout analysis
Imports IronOcr
Imports System
' Create an instance of the IronTesseract class for OCR processing
Private ocr = New IronTesseract()
' Create an OcrInput object to load and preprocess images
Private input = New OcrInput()
' Specify which pages to extract from multi-page documents
Private pageIndices = New Integer() { 1, 2 }
' Load specific frames from a TIFF file
' IronOCR automatically detects and handles various image formats
input.LoadImageFrames("img\example.tiff", pageIndices)
' Apply automatic image enhancement filters
' These filters dramatically improve accuracy on imperfect scans
input.DeNoise() ' Removes digital artifacts and speckles
input.Deskew() ' Corrects rotation up to 15 degrees
' Perform OCR with enhanced accuracy algorithms
Dim result As OcrResult = ocr.Read(input)
' Access the extracted text with confidence metrics
Console.WriteLine(result.Text)
' Additional accuracy features available:
' - result.Confidence: Overall accuracy percentage
' - result.Pages[0].Words: Word-level confidence scores
' - result.Blocks: Structured document layout analysis
using IronOcr;var ocr = new IronTesseract();ocr.Language = OcrLanguage.Arabic;using var input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames("img/arabic.gif", pageindices);// Add image filters if needed// In this case, even thought input is very low quality// IronTesseract can read what conventional Tesseract cannot.var result = ocr.Read(input);// Console can't print Arabic on Windows easily.// Let's save to disk instead.result.SaveAsTextFile("arabic.txt");
using IronOcr;
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using var input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
var result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");
ImportsIronOcrPrivate ocr = New IronTesseract()ocr.Language = OcrLanguage.ArabicDim input = New OcrInput()Dim pageindices = New Integer() { 1, 2 }input.LoadImageFrames("img/arabic.gif", pageindices)' Add image filters if needed' In this case, even thought input is very low quality' IronTesseract can read what conventional Tesseract cannot.Dim result = ocr.Read(input)' Console can't print Arabic on Windows easily.' Let's save to disk instead.result.SaveAsTextFile("arabic.txt")
Imports IronOcr
Private ocr = New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Dim input = New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
using IronOcr;// For the Chinese Language Pack:// PM> Install IronOcr.Languages.ChineseSimplifiedvar ocr = new IronTesseract();ocr.Language = OcrLanguage.ChineseSimplified;ocr.AddSecondaryLanguage(OcrLanguage.English);// We can add any number of languagesusing var input = new OcrInput();input.LoadPdf("multi-language.pdf");var result = ocr.Read(input);result.SaveAsTextFile("results.txt");
using IronOcr;
// For the Chinese Language Pack:
// PM> Install IronOcr.Languages.ChineseSimplified
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
ocr.AddSecondaryLanguage(OcrLanguage.English);
// We can add any number of languages
using var input = new OcrInput();
input.LoadPdf("multi-language.pdf");
var result = ocr.Read(input);
result.SaveAsTextFile("results.txt");
ImportsIronOcr' For the Chinese Language Pack:' PM> Install IronOcr.Languages.ChineseSimplifiedPrivate ocr = New IronTesseract()ocr.Language = OcrLanguage.ChineseSimplifiedocr.AddSecondaryLanguage(OcrLanguage.English)' We can add any number of languagesDim input = New OcrInput()input.LoadPdf("multi-language.pdf")Dim result = ocr.Read(input)result.SaveAsTextFile("results.txt")
Imports IronOcr
' For the Chinese Language Pack:
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr = New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
ocr.AddSecondaryLanguage(OcrLanguage.English)
' We can add any number of languages
Dim input = New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result = ocr.Read(input)
result.SaveAsTextFile("results.txt")
這個精簡的 API 消除了傳統 Tesseract 整合的複雜性。 每個方法都包括全面的 XML 文件,讓您能夠直接在 IDE 中探索功能。廣泛的 API 文件提供了每個功能的詳細範例。
using IronOcr;// Configure IronTesseract for Arabic text recognitionvar ocr = new IronTesseract{ // Set primary language to Arabic // Automatically handles right-to-left textLanguage = OcrLanguage.Arabic};// Load Arabic documents for processingusing var input = new OcrInput();var pageIndices = new int[] { 1, 2 };input.LoadImageFrames("img/arabic.gif", pageIndices);// IronOCR includes specialized preprocessing for Arabic scripts// Handles cursive text and diacritical marks automatically// Perform OCR with language-specific optimizationsvar result = ocr.Read(input);// Save results with proper Unicode encoding// Preserves Arabic text formatting and directionresult.SaveAsTextFile("arabic.txt");// Advanced Arabic features:// - Mixed Arabic/English document support// - Automatic number conversion (Eastern/Western Arabic)// - Font-specific optimization for common Arabic typefaces
using IronOcr;
// Configure IronTesseract for Arabic text recognition
var ocr = new IronTesseract
{
// Set primary language to Arabic
// Automatically handles right-to-left text
Language = OcrLanguage.Arabic
};
// Load Arabic documents for processing
using var input = new OcrInput();
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageIndices);
// IronOCR includes specialized preprocessing for Arabic scripts
// Handles cursive text and diacritical marks automatically
// Perform OCR with language-specific optimizations
var result = ocr.Read(input);
// Save results with proper Unicode encoding
// Preserves Arabic text formatting and direction
result.SaveAsTextFile("arabic.txt");
// Advanced Arabic features:
// - Mixed Arabic/English document support
// - Automatic number conversion (Eastern/Western Arabic)
// - Font-specific optimization for common Arabic typefaces
ImportsIronOcr' Configure IronTesseract for Arabic text recognitionPrivate ocr = New IronTesseractWith {.Language = OcrLanguage.Arabic}' Load Arabic documents for processingPrivate input = New OcrInput()Private pageIndices = New Integer() { 1, 2 }input.LoadImageFrames("img/arabic.gif", pageIndices)' IronOCR includes specialized preprocessing for Arabic scripts' Handles cursive text and diacritical marks automatically' Perform OCR with language-specific optimizationsDim result = ocr.Read(input)' Save results with proper Unicode encoding' Preserves Arabic text formatting and directionresult.SaveAsTextFile("arabic.txt")' Advanced Arabic features:' - Mixed Arabic/English document support' - Automatic number conversion (Eastern/Western Arabic)' - Font-specific optimization for common Arabic typefaces
Imports IronOcr
' Configure IronTesseract for Arabic text recognition
Private ocr = New IronTesseract With {.Language = OcrLanguage.Arabic}
' Load Arabic documents for processing
Private input = New OcrInput()
Private pageIndices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageIndices)
' IronOCR includes specialized preprocessing for Arabic scripts
' Handles cursive text and diacritical marks automatically
' Perform OCR with language-specific optimizations
Dim result = ocr.Read(input)
' Save results with proper Unicode encoding
' Preserves Arabic text formatting and direction
result.SaveAsTextFile("arabic.txt")
' Advanced Arabic features:
' - Mixed Arabic/English document support
' - Automatic number conversion (Eastern/Western Arabic)
' - Font-specific optimization for common Arabic typefaces
多語言文件處理
using IronOcr;// Install language packs via NuGet:// PM> Install-Package IronOcr.Languages.ChineseSimplified// Configure multi-language OCRvar ocr = new IronTesseract();// Set primary language for majority contentocr.Language = OcrLanguage.ChineseSimplified;// Add secondary language for mixed content// Perfect for documents with Chinese text and English metadataocr.AddSecondaryLanguage(OcrLanguage.English);// Process multi-language PDFs efficientlyusing var input = new OcrInput();input.LoadPdf("multi-language.pdf");// IronOCR automatically detects and switches between languages// Maintains high accuracy across language boundariesvar result = ocr.Read(input);// Export preserves all languages correctlyresult.SaveAsTextFile("results.txt");// Supported scenarios:// - Technical documents with English terms in foreign text// - Multilingual forms and applications // - International business documents// - Mixed-script content (Latin, CJK, Arabic, etc.)
using IronOcr;
// Install language packs via NuGet:
// PM> Install-Package IronOcr.Languages.ChineseSimplified
// Configure multi-language OCR
var ocr = new IronTesseract();
// Set primary language for majority content
ocr.Language = OcrLanguage.ChineseSimplified;
// Add secondary language for mixed content
// Perfect for documents with Chinese text and English metadata
ocr.AddSecondaryLanguage(OcrLanguage.English);
// Process multi-language PDFs efficiently
using var input = new OcrInput();
input.LoadPdf("multi-language.pdf");
// IronOCR automatically detects and switches between languages
// Maintains high accuracy across language boundaries
var result = ocr.Read(input);
// Export preserves all languages correctly
result.SaveAsTextFile("results.txt");
// Supported scenarios:
// - Technical documents with English terms in foreign text
// - Multilingual forms and applications
// - International business documents
// - Mixed-script content (Latin, CJK, Arabic, etc.)
ImportsIronOcr' Install language packs via NuGet:' PM> Install-Package IronOcr.Languages.ChineseSimplified' Configure multi-language OCRPrivate ocr = New IronTesseract()' Set primary language for majority contentocr.Language = OcrLanguage.ChineseSimplified' Add secondary language for mixed content' Perfect for documents with Chinese text and English metadataocr.AddSecondaryLanguage(OcrLanguage.English)' Process multi-language PDFs efficientlyDim input = New OcrInput()input.LoadPdf("multi-language.pdf")' IronOCR automatically detects and switches between languages' Maintains high accuracy across language boundariesDim result = ocr.Read(input)' Export preserves all languages correctlyresult.SaveAsTextFile("results.txt")' Supported scenarios:' - Technical documents with English terms in foreign text' - Multilingual forms and applications ' - International business documents' - Mixed-script content (Latin, CJK, Arabic, etc.)
Imports IronOcr
' Install language packs via NuGet:
' PM> Install-Package IronOcr.Languages.ChineseSimplified
' Configure multi-language OCR
Private ocr = New IronTesseract()
' Set primary language for majority content
ocr.Language = OcrLanguage.ChineseSimplified
' Add secondary language for mixed content
' Perfect for documents with Chinese text and English metadata
ocr.AddSecondaryLanguage(OcrLanguage.English)
' Process multi-language PDFs efficiently
Dim input = New OcrInput()
input.LoadPdf("multi-language.pdf")
' IronOCR automatically detects and switches between languages
' Maintains high accuracy across language boundaries
Dim result = ocr.Read(input)
' Export preserves all languages correctly
result.SaveAsTextFile("results.txt")
' Supported scenarios:
' - Technical documents with English terms in foreign text
' - Multilingual forms and applications
' - International business documents
' - Mixed-script content (Latin, CJK, Arabic, etc.)
How does IronOCR handle OCR for different image formats?
IronOCR automatically manages image conversions for various formats such as JPEG, PNG, BMP, and supports .NET types, providing a consistent API for all image processing needs.
Why is IronOCR a preferred choice for professional OCR solutions in C#?
IronOCR is preferred for professional OCR due to its ease of use, robust feature set, cross-platform compatibility, and reliable support, making it ideal for production environments.