與其他元件比較 進階文件分析 Kannapat Udonpant 更新:2026年1月5日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 Tesseract OCR 需要先將 PDF 頁面轉換為圖像才能提取文本,而 IronOCR 提供原生 PDF 支援和內建預處理功能,為 .NET 開發人員大規模處理掃描文件提供了一種直接的方法。 從掃描的 PDF 文件中提取文字是 C# 和 .NET 應用程式中的常見需求。 無論是處理發票、數位化掃描文檔,還是自動化資料輸入工作流程,開發人員都需要可靠的OCR 解決方案,以有效率地將 PDF 文件轉換為可編輯和可搜尋的資料。 雖然Tesseract OCR是由 Google 維護的廣泛使用的開源光學字元辨識引擎,但許多 .NET 開發人員在處理 PDF 內容時會遇到重大挑戰。 本文比較分析如何使用 Tesseract OCR 和IronOCR在 C# 中執行PDF 到文本的轉換,並提供了原始程式碼範例和關於為生產系統選擇合適的OCR 庫的實用指導。 這有助於開發人員在建立生產 OCR 系統時了解每種方法的架構影響。 這些OCR解決方案在PDF/掃描PDF處理上有何不同? 在深入探討實作細節之前,這裡先將掃描 PDF 檔案中的文字辨識的關鍵功能並排比較: 特徵 超立方體 IronOCR 原生 PDF 輸入 否(需要轉換為影像) 是的 安裝 多重依賴 單一 NuGet 套件 受密碼保護的PDF文件 不支援 支援 影像預處理 手動(外部工具) 內建過濾器 語言支援 100多種語言 127+ 種語言 授權 Apache 2.0(免費) 商業的 .NET 集成 透過 .NET 封裝器 原生 C# 函式庫 影像格式 PNG、JPEG、TIFF、BMP PNG、JPEG、TIFF、BMP、GIF、PDF 輸出選項 純文字、hOCR、HTML 純文字、可搜尋 PDF、hOCR 比較結果顯示, IronOCR提供了更完整的 PDF 處理功能,特別適用於需要產生可搜尋 PDF和條碼辨識的企業文件管理系統。 Tesseract 如何處理 PDF 檔案並提取文字? Tesseract OCR引擎本身並不支援PDF文件輸入。 根據Tesseract 官方文檔,開發人員必須先將 PDF 頁面轉換為 PNG 或 JPEG 等輸入影像格式,然後才能執行 OCR。 此過程需要像 Ghostscript、Docotic.Pdf 或類似工具這樣的額外庫來渲染每個頁面。 轉換工作流程增加了生產系統的複雜性。 以下是一個簡化的 Tesseract 工作流程範例,用於從 PDF 文件中提取文字(C#): using Tesseract; using System.Drawing; using System.Threading.Tasks; // Step 1: Convert PDF page to PNG image (requires separate PDF library) // This example assumes you've already converted the scanned PDF to an image string imagePath = "document-scan.png"; // Step 2: Initialize Tesseract with language data files path var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default); // Step 3: Load the input image and process var img = Pix.LoadFromFile(imagePath); var page = engine.Process(img); // Step 4: Extract the recognized text string extractedText = page.GetText(); Console.WriteLine($"Confidence: {page.GetMeanConfidence()}"); Console.WriteLine(extractedText); // Optional: Get detailed results with bounding boxes using (var iter = page.GetIterator()) { iter.Begin(); do { if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out var bounds)) { var word = iter.GetText(PageIteratorLevel.Word); Console.WriteLine($"Word: {word} at {bounds}"); } } while (iter.Next(PageIteratorLevel.Word)); } // Clean up resources page.Dispose(); img.Dispose(); engine.Dispose(); using Tesseract; using System.Drawing; using System.Threading.Tasks; // Step 1: Convert PDF page to PNG image (requires separate PDF library) // This example assumes you've already converted the scanned PDF to an image string imagePath = "document-scan.png"; // Step 2: Initialize Tesseract with language data files path var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default); // Step 3: Load the input image and process var img = Pix.LoadFromFile(imagePath); var page = engine.Process(img); // Step 4: Extract the recognized text string extractedText = page.GetText(); Console.WriteLine($"Confidence: {page.GetMeanConfidence()}"); Console.WriteLine(extractedText); // Optional: Get detailed results with bounding boxes using (var iter = page.GetIterator()) { iter.Begin(); do { if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out var bounds)) { var word = iter.GetText(PageIteratorLevel.Word); Console.WriteLine($"Word: {word} at {bounds}"); } } while (iter.Next(PageIteratorLevel.Word)); } // Clean up resources page.Dispose(); img.Dispose(); engine.Dispose(); Imports Tesseract Imports System.Drawing Imports System.Threading.Tasks ' Step 1: Convert PDF page to PNG image (requires separate PDF library) ' This example assumes you've already converted the scanned PDF to an image Dim imagePath As String = "document-scan.png" ' Step 2: Initialize Tesseract with language data files path Dim engine As New TesseractEngine("./tessdata", "eng", EngineMode.Default) ' Step 3: Load the input image and process Dim img As Pix = Pix.LoadFromFile(imagePath) Dim page As Page = engine.Process(img) ' Step 4: Extract the recognized text Dim extractedText As String = page.GetText() Console.WriteLine($"Confidence: {page.GetMeanConfidence()}") Console.WriteLine(extractedText) ' Optional: Get detailed results with bounding boxes Using iter As ResultIterator = page.GetIterator() iter.Begin() Do Dim bounds As Rect If iter.TryGetBoundingBox(PageIteratorLevel.Word, bounds) Then Dim word As String = iter.GetText(PageIteratorLevel.Word) Console.WriteLine($"Word: {word} at {bounds}") End If Loop While iter.Next(PageIteratorLevel.Word) End Using ' Clean up resources page.Dispose() img.Dispose() engine.Dispose() $vbLabelText $csharpLabel 這段程式碼示範了使用 NuGet 上提供的 .NET 封裝器的標準 Tesseract 方法。 engine初始化需要指向包含語言資料檔案的tessdata資料夾的路徑,這些檔案必須從tessdata 儲存庫單獨下載。 img賦值語句以 Leptonica 的 PIX 格式載入輸入影像-這是一個非託管的 C++ 對象,需要仔細的記憶體管理以防止記憶體洩漏。 Process的page結果執行實際的光學字元辨識操作。 對於生產環境,處理多頁文件需要額外的協調: // Example: Processing multiple PDF pages (after conversion) public async Task<string> ProcessMultiPagePdf(string[] imagePaths) { var results = new StringBuilder(); var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default); foreach (var imagePath in imagePaths) { using (var img = Pix.LoadFromFile(imagePath)) using (var page = engine.Process(img)) { results.AppendLine($"Page confidence: {page.GetMeanConfidence():F2}"); results.AppendLine(page.GetText()); results.AppendLine("---"); } } engine.Dispose(); return results.ToString(); } // Example: Processing multiple PDF pages (after conversion) public async Task<string> ProcessMultiPagePdf(string[] imagePaths) { var results = new StringBuilder(); var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default); foreach (var imagePath in imagePaths) { using (var img = Pix.LoadFromFile(imagePath)) using (var page = engine.Process(img)) { results.AppendLine($"Page confidence: {page.GetMeanConfidence():F2}"); results.AppendLine(page.GetText()); results.AppendLine("---"); } } engine.Dispose(); return results.ToString(); } Imports System.Text Imports Tesseract Public Async Function ProcessMultiPagePdf(imagePaths As String()) As Task(Of String) Dim results As New StringBuilder() Dim engine As New TesseractEngine("./tessdata", "eng", EngineMode.Default) For Each imagePath In imagePaths Using img = Pix.LoadFromFile(imagePath) Using page = engine.Process(img) results.AppendLine($"Page confidence: {page.GetMeanConfidence():F2}") results.AppendLine(page.GetText()) results.AppendLine("---") End Using End Using Next engine.Dispose() Return results.ToString() End Function $vbLabelText $csharpLabel 為什麼 Tesseract 需要先進行影像轉換? PDF 檢視器顯示發票 #1001,總金額為 500 美元,示範掃描 PDF 處理的文件檢視功能。 Tesseract 的架構完全專注於影像處理,而不是文件處理。 這種設計選擇意味著開發人員必須自行管理 PDF 到圖像的轉換流程,這在處理受密碼保護的 PDF 、多頁文件或包含文字和圖像的混合內容 PDF時會增加複雜性。 轉換品質直接影響OCR 的準確性,因此正確的DPI 設定對於提高結果至關重要。 基礎 Tesseract 處理能帶來哪些結果? Visual Studio 偵錯控制台顯示已成功從 .NET 9.0 應用程式中提取 PDF 文本,內容為"發票 #1001"和"總計:$500.00"。 這裡的主要限制是,這段程式碼只能處理圖像檔案。 要從多頁 PDF 文件中提取文本,開發人員需要實現額外的邏輯,將每一頁渲染為 PNG 圖像,保存臨時文件,使用OCR 引擎分別處理每一頁,然後匯總識別出的文本結果。 這種多步驟工作流程增加了複雜性,並引入了潛在的故障點。 使用數位相機拍攝的影像或白色背景的文件可能需要預處理才能實現準確的文字辨識。 置信度評分有助於驗證萃取質量,但需要人工解釋和閾值設定。 IronOCR 如何直接處理 PDF 和影像格式? IronOCR提供原生 PDF 支持,無需將掃描文件轉換為中間影像格式。 該庫在內部處理 PDF 渲染,簡化了.NET 應用程式的工作流程。 這種方法對於效能和可靠性至關重要的企業文件處理非常有價值。 整合的Tesseract 5 引擎在保持跨平台相容性的同時,提高了精度,優於早期版本。 using IronOcr; using System.Linq; // Initialize the OCR engine (improved Tesseract 5) var ocr = new IronTesseract(); // Configure for improved accuracy ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto; ocr.Configuration.ReadBarCodes = true; // Also detect barcodes/QR codes // Load PDF document directly - no conversion needed var input = new OcrInput(); input.LoadPdf("scanned-document.pdf", Password: "optional-password"); // Optional: Pre-process for better accuracy on low-quality scans input.DeNoise(); // Remove noise from scanned paper documents input.Deskew(); // Fix rotation from images captured at angles input.EnhanceResolution(300); // Ensure improved DPI // Extract text from all pages and create searchable data OcrResult result = ocr.Read(input); // Access detailed results Console.WriteLine($"Overall Confidence: {result.Confidence}%"); Console.WriteLine($"Pages Processed: {result.Pages.Count()}"); Console.WriteLine(result.Text); // Export as searchable PDF result.SaveAsSearchablePdf("searchable-output.pdf"); using IronOcr; using System.Linq; // Initialize the OCR engine (improved Tesseract 5) var ocr = new IronTesseract(); // Configure for improved accuracy ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto; ocr.Configuration.ReadBarCodes = true; // Also detect barcodes/QR codes // Load PDF document directly - no conversion needed var input = new OcrInput(); input.LoadPdf("scanned-document.pdf", Password: "optional-password"); // Optional: Pre-process for better accuracy on low-quality scans input.DeNoise(); // Remove noise from scanned paper documents input.Deskew(); // Fix rotation from images captured at angles input.EnhanceResolution(300); // Ensure improved DPI // Extract text from all pages and create searchable data OcrResult result = ocr.Read(input); // Access detailed results Console.WriteLine($"Overall Confidence: {result.Confidence}%"); Console.WriteLine($"Pages Processed: {result.Pages.Count()}"); Console.WriteLine(result.Text); // Export as searchable PDF result.SaveAsSearchablePdf("searchable-output.pdf"); Imports IronOcr Imports System.Linq ' Initialize the OCR engine (improved Tesseract 5) Dim ocr As New IronTesseract() ' Configure for improved accuracy ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto ocr.Configuration.ReadBarCodes = True ' Also detect barcodes/QR codes ' Load PDF document directly - no conversion needed Dim input As New OcrInput() input.LoadPdf("scanned-document.pdf", Password:="optional-password") ' Optional: Pre-process for better accuracy on low-quality scans input.DeNoise() ' Remove noise from scanned paper documents input.Deskew() ' Fix rotation from images captured at angles input.EnhanceResolution(300) ' Ensure improved DPI ' Extract text from all pages and create searchable data Dim result As OcrResult = ocr.Read(input) ' Access detailed results Console.WriteLine($"Overall Confidence: {result.Confidence}%") Console.WriteLine($"Pages Processed: {result.Pages.Count()}") Console.WriteLine(result.Text) ' Export as searchable PDF result.SaveAsSearchablePdf("searchable-output.pdf") $vbLabelText $csharpLabel IronTesseract類別封裝了一個專為 .NET Core 和 .NET Framework 環境而建置的最佳化Tesseract 5 引擎。 與標準的 .NET 封裝器不同,此實作可自動處理記憶體管理,並包含針對 .NET 應用程式的效能最佳化。 OcrInput類別透過LoadPdf方法直接接受 PDF 文件,在內部渲染頁面,無需下載額外的庫。 DeNoise()和Deskew()方法應用影像預處理濾波器,可顯著提高掃描文件的精確度,尤其對於有背景雜訊、斑點或輕微旋轉的文件。 當處理在非理想條件下拍攝的真實紙質掃描文件時,這些過濾器尤其有價值。 OcrResult物件包含提取的純文字以及用於後處理驗證的附加元數據,例如置信度分數和字元位置。 您也可以將結果輸出為可搜尋的 PDF 或 HTML 格式。 為了更好地控制,開發人員可以指定PDF 文件中的特定頁面甚至區域: using IronOcr; using System.Drawing; var ocr = new IronTesseract(); // Advanced configuration for specific document types ocr.Configuration = new TesseractConfiguration() { WhiteListCharacters = "0123456789.$,", // For financial documents BlackListCharacters = "`~", PageSegmentationMode = TesseractPageSegmentationMode.SingleColumn }; // Load specific pages from a PDF file (pages 1 and 2) var input = new OcrInput(); input.LoadPdfPages("web-report.pdf", new[] { 0, 1 }); // Target specific regions for extraction (e.g., invoice totals) var cropRegion = new CropRectangle(x: 100, y: 500, width: 400, height: 200); foreach (var page in input.Pages) { page.AddCropRegion(cropRegion); } // Perform OCR and get searchable text OcrResult result = ocr.Read(input); // Access structured data foreach (var page in result.Pages) { Console.WriteLine($"Page {page.PageNumber}:"); foreach (var paragraph in page.Paragraphs) { Console.WriteLine($" Paragraph (Confidence: {paragraph.Confidence}%):"); Console.WriteLine($" {paragraph.Text}"); } } using IronOcr; using System.Drawing; var ocr = new IronTesseract(); // Advanced configuration for specific document types ocr.Configuration = new TesseractConfiguration() { WhiteListCharacters = "0123456789.$,", // For financial documents BlackListCharacters = "`~", PageSegmentationMode = TesseractPageSegmentationMode.SingleColumn }; // Load specific pages from a PDF file (pages 1 and 2) var input = new OcrInput(); input.LoadPdfPages("web-report.pdf", new[] { 0, 1 }); // Target specific regions for extraction (e.g., invoice totals) var cropRegion = new CropRectangle(x: 100, y: 500, width: 400, height: 200); foreach (var page in input.Pages) { page.AddCropRegion(cropRegion); } // Perform OCR and get searchable text OcrResult result = ocr.Read(input); // Access structured data foreach (var page in result.Pages) { Console.WriteLine($"Page {page.PageNumber}:"); foreach (var paragraph in page.Paragraphs) { Console.WriteLine($" Paragraph (Confidence: {paragraph.Confidence}%):"); Console.WriteLine($" {paragraph.Text}"); } } Imports IronOcr Imports System.Drawing Dim ocr = New IronTesseract() ' Advanced configuration for specific document types ocr.Configuration = New TesseractConfiguration() With { .WhiteListCharacters = "0123456789.$,", ' For financial documents .BlackListCharacters = "`~", .PageSegmentationMode = TesseractPageSegmentationMode.SingleColumn } ' Load specific pages from a PDF file (pages 1 and 2) Dim input = New OcrInput() input.LoadPdfPages("web-report.pdf", {0, 1}) ' Target specific regions for extraction (e.g., invoice totals) Dim cropRegion = New CropRectangle(x:=100, y:=500, width:=400, height:=200) For Each page In input.Pages page.AddCropRegion(cropRegion) Next ' Perform OCR and get searchable text Dim result As OcrResult = ocr.Read(input) ' Access structured data For Each page In result.Pages Console.WriteLine($"Page {page.PageNumber}:") For Each paragraph In page.Paragraphs Console.WriteLine($" Paragraph (Confidence: {paragraph.Confidence}%):") Console.WriteLine($" {paragraph.Text}") Next Next $vbLabelText $csharpLabel LoadPdfPages方法接受一個從零開始的頁面索引值數組,允許對大型 PDF 文件進行選擇性處理,而無需將每一頁都載入到記憶體中。 該 API 還透過額外的語言包支援多種語言,這些語言包配置 Tesseract 以識別同一文件中的多種語言。 基於區域的提取功能對於處理發票、表格和財務報表等結構化文件至關重要。 裁切區域功能可以針對特定區域,例如頁首、頁尾或資料表。 IronOCR可以處理哪些類型的PDF文件? IronPDF 主頁展示了完整的 C# PDF 庫功能,包括 HTML 轉 PDF 轉換、編輯以及超過 1500 萬次的 NuGet 下載。 IronOCR 可以處理各種 PDF 類型,包括掃描文件、原生文字 PDF 、混合內容和受密碼保護的文件。 該程式庫會自動偵測 PDF 是否包含可擷取的文字或需要OCR 處理,並針對每種情況最佳化效能。 這種多功能性使其適用於文件數位化專案和自動資料擷取。 流支援功能允許直接從記憶體處理文件而無需臨時文件,非常適合雲端部署和安全環境。 頁面特定處理是如何運作的? IronPDF 文件提供了使用 RenderUrlAsPdf、RenderHtmlFileAsPdf 和 RenderHtmlAsPdf 方法將 HTML 轉換為 PDF 的 C# 程式碼範例。 頁面特定處理能夠僅針對相關頁面,從而實現大型文件的高效處理。 對於需要從多頁文件的特定部分提取資料的 批次系統而言,這種功能至關重要。 非同步支援允許並行處理多個文檔,而不會阻塞主線程。 中止令牌等高級功能為長時間運行的操作提供取消支持,而逾時配置可防止資源耗盡。 ## 設定和工作流程的主要差異是什麼? 為什麼 Tesseract 的安裝更複雜? Tesseract需要在 Visual Studio 中安裝多個元件才能正常運作:Tesseract OCR 引擎二進位檔案、 Leptonica 映像庫、Windows 版Visual C++ 可再發行元件包,以及每種待辨識語言的語言資料檔案。開發人員必須下載 tessdata 檔案並正確配置路徑。 跨平台部署到Azure 、 Docker 容器或Linux 伺服器等環境通常需要針對特定平台進行設定和依賴路徑故障排除。 使用字體和可編輯文件可能需要額外的設定。 libgdiplus依賴項在非 Windows 平台上會帶來額外的挑戰。 當處理Azure Functions或AWS Lambda部署時,依賴項管理會變得特別具有挑戰性,因為執行時間環境對外部相依性和記憶體分配有嚴格的限制。 不支援 AVX 指令集的舊款 CPU 上出現的 SEHException 錯誤又增加了一層複雜度。 開發人員經常會遇到運行時資料夾權限和tessdata 位置錯誤的問題。 IronOCR將安裝簡化為一個單獨的 NuGet 套件,無需任何外部相依性: Install-Package IronOcr Install-Package IronOcr SHELL 對於特殊文件類型,附加軟體包可增強其功能: Install-Package IronOcr.Extensions.AdvancedScan # For specific languages Install-Package IronOcr.Languages.French Install-Package IronOcr.Languages.Japanese Install-Package IronOcr.Extensions.AdvancedScan # For specific languages Install-Package IronOcr.Languages.French Install-Package IronOcr.Languages.Japanese SHELL NuGet 套件管理器控制台顯示 IronOCR 安裝成功,自動相依性解析大約在 20 秒內完成。 庫中已包含所有必需元件。 其他語言的語言套件以單獨的 NuGet 套件形式提供,安裝同樣簡便,無需手動檔案管理和資料夾設定。 預設情況下,OCR 函式庫支援Windows 、 macOS和Linux上的.NET Framework 4.6.2+ 、. NET Core和 .NET 5-10。 文件有助於開發人員快速建立 OCR 解決方案。 Windows 安裝程式為企業環境提供了一種替代安裝方法。 PDF 處理工作流程有何異同? Tesseract 的 PDF 文字擷取方法涉及多個步驟:載入 PDF 文件 → 使用單獨的庫將每一頁轉換為 PNG 等圖像格式 → 使用 PIX 格式將圖像載入到 Tesseract 中 → 處理每一頁 → 匯總所有頁面上的字串結果。 每個步驟都會引入潛在的故障點,需要進行錯誤處理,並增加程式碼庫的整體大小。開發人員還必須謹慎處理記憶體管理,以防止未託管的 PIX 物件造成記憶體洩漏。 範例程式碼通常需要幾十行才能處理基本的 PDF 處理。 System.Drawing 依賴項在.NET 7+ 環境中會帶來額外的挑戰。 IronOCR 將整個工作流程簡化為:載入 PDF → 處理 → 查看結果。 該庫在內部管理 PDF 渲染、記憶體分配、多頁處理和結果聚合。 這種簡化的方法降低了程式碼的複雜性和開發時間,同時最大限度地減少了錯誤的可能性。 透過一次 API 調用,即可將識別出的文字儲存為純文字、可搜尋的 PDF或其他格式。 導出功能包括提取 OCR 元素的圖像以進行驗證。 以下是一個可用於生產環境的範例,展示了錯誤處理和進度追蹤: using IronOcr; using System; using System.Threading.Tasks; public class PdfOcrService { private readonly IronTesseract _ocr; public PdfOcrService() { _ocr = new IronTesseract(); // Subscribe to progress events _ocr.OcrProgress += (sender, e) => { Console.WriteLine($"Processing page {e.PagesComplete}/{e.TotalPages} - {e.ProgressPercent}%"); }; } public async Task<OcrResult> ProcessPdfWithErrorHandling(string pdfPath) { try { var input = new OcrInput(); // Check file size for large documents var fileInfo = new System.IO.FileInfo(pdfPath); if (fileInfo.Length > 100_000_000) // 100MB { // Use lower DPI for large files input.TargetDPI = 150; } input.LoadPdf(pdfPath); // Apply filters based on document quality assessment if (RequiresPreprocessing(input)) { input.DeNoise(); input.Deskew(); input.EnhanceResolution(300); } // Process with timeout protection using (var cts = new System.Threading.CancellationTokenSource(TimeSpan.FromMinutes(5))) { return await _ocr.ReadAsync(input, cts.Token); } } catch (Exception ex) { // Log and handle specific exceptions throw new ApplicationException($"OCR processing failed: {ex.Message}", ex); } } private bool RequiresPreprocessing(OcrInput input) { // Implement quality assessment logic return true; } } using IronOcr; using System; using System.Threading.Tasks; public class PdfOcrService { private readonly IronTesseract _ocr; public PdfOcrService() { _ocr = new IronTesseract(); // Subscribe to progress events _ocr.OcrProgress += (sender, e) => { Console.WriteLine($"Processing page {e.PagesComplete}/{e.TotalPages} - {e.ProgressPercent}%"); }; } public async Task<OcrResult> ProcessPdfWithErrorHandling(string pdfPath) { try { var input = new OcrInput(); // Check file size for large documents var fileInfo = new System.IO.FileInfo(pdfPath); if (fileInfo.Length > 100_000_000) // 100MB { // Use lower DPI for large files input.TargetDPI = 150; } input.LoadPdf(pdfPath); // Apply filters based on document quality assessment if (RequiresPreprocessing(input)) { input.DeNoise(); input.Deskew(); input.EnhanceResolution(300); } // Process with timeout protection using (var cts = new System.Threading.CancellationTokenSource(TimeSpan.FromMinutes(5))) { return await _ocr.ReadAsync(input, cts.Token); } } catch (Exception ex) { // Log and handle specific exceptions throw new ApplicationException($"OCR processing failed: {ex.Message}", ex); } } private bool RequiresPreprocessing(OcrInput input) { // Implement quality assessment logic return true; } } Imports IronOcr Imports System Imports System.Threading.Tasks Imports System.IO Public Class PdfOcrService Private ReadOnly _ocr As IronTesseract Public Sub New() _ocr = New IronTesseract() ' Subscribe to progress events AddHandler _ocr.OcrProgress, Sub(sender, e) Console.WriteLine($"Processing page {e.PagesComplete}/{e.TotalPages} - {e.ProgressPercent}%") End Sub End Sub Public Async Function ProcessPdfWithErrorHandling(pdfPath As String) As Task(Of OcrResult) Try Dim input As New OcrInput() ' Check file size for large documents Dim fileInfo As New FileInfo(pdfPath) If fileInfo.Length > 100_000_000 Then ' 100MB ' Use lower DPI for large files input.TargetDPI = 150 End If input.LoadPdf(pdfPath) ' Apply filters based on document quality assessment If RequiresPreprocessing(input) Then input.DeNoise() input.Deskew() input.EnhanceResolution(300) End If ' Process with timeout protection Using cts As New Threading.CancellationTokenSource(TimeSpan.FromMinutes(5)) Return Await _ocr.ReadAsync(input, cts.Token) End Using Catch ex As Exception ' Log and handle specific exceptions Throw New ApplicationException($"OCR processing failed: {ex.Message}", ex) End Try End Function Private Function RequiresPreprocessing(input As OcrInput) As Boolean ' Implement quality assessment logic Return True End Function End Class $vbLabelText $csharpLabel 此模式展示了 IronOCR 的非同步功能和進度追蹤如何建立可靠的生產系統,以處理大型文件、提供使用者回饋並實現適當的逾時處理。 詳細的配置選項允許針對特定文件類型進行微調。 對於特殊文檔,IronOCR 提供專門的方法: // Process different document types with optimized settings var ocr = new IronTesseract(); // For license plates var licensePlateResult = ocr.ReadLicensePlate("car-photo.jpg"); Console.WriteLine($"License Plate: {licensePlateResult.Text}"); // For passports with MRZ var passportResult = ocr.ReadPassport("passport-scan.pdf"); Console.WriteLine($"Passport Number: {passportResult.PassportNumber}"); Console.WriteLine($"Name: {passportResult.GivenNames} {passportResult.Surname}"); // For handwritten text var handwritingResult = ocr.ReadHandwriting("handwritten-note.png"); Console.WriteLine($"Handwriting: {handwritingResult.Text}"); // For MICR cheques var chequeResult = ocr.ReadMicrCheque("cheque-image.tiff"); Console.WriteLine($"Account: {chequeResult.AccountNumber}"); Console.WriteLine($"Routing: {chequeResult.RoutingNumber}"); // Process different document types with optimized settings var ocr = new IronTesseract(); // For license plates var licensePlateResult = ocr.ReadLicensePlate("car-photo.jpg"); Console.WriteLine($"License Plate: {licensePlateResult.Text}"); // For passports with MRZ var passportResult = ocr.ReadPassport("passport-scan.pdf"); Console.WriteLine($"Passport Number: {passportResult.PassportNumber}"); Console.WriteLine($"Name: {passportResult.GivenNames} {passportResult.Surname}"); // For handwritten text var handwritingResult = ocr.ReadHandwriting("handwritten-note.png"); Console.WriteLine($"Handwriting: {handwritingResult.Text}"); // For MICR cheques var chequeResult = ocr.ReadMicrCheque("cheque-image.tiff"); Console.WriteLine($"Account: {chequeResult.AccountNumber}"); Console.WriteLine($"Routing: {chequeResult.RoutingNumber}"); ' Process different document types with optimized settings Dim ocr = New IronTesseract() ' For license plates Dim licensePlateResult = ocr.ReadLicensePlate("car-photo.jpg") Console.WriteLine($"License Plate: {licensePlateResult.Text}") ' For passports with MRZ Dim passportResult = ocr.ReadPassport("passport-scan.pdf") Console.WriteLine($"Passport Number: {passportResult.PassportNumber}") Console.WriteLine($"Name: {passportResult.GivenNames} {passportResult.Surname}") ' For handwritten text Dim handwritingResult = ocr.ReadHandwriting("handwritten-note.png") Console.WriteLine($"Handwriting: {handwritingResult.Text}") ' For MICR cheques Dim chequeResult = ocr.ReadMicrCheque("cheque-image.tiff") Console.WriteLine($"Account: {chequeResult.AccountNumber}") Console.WriteLine($"Routing: {chequeResult.RoutingNumber}") $vbLabelText $csharpLabel 這些專門的方法使用機器學習模型和針對特定文件類型的最佳化配置,比通用 OCR 方法提供更高的準確性。 車牌識別可處理各種國際格式,而護照讀取可自動提取 MRZ 資料。 手寫辨識對英文文字的準確率約為 90%, MICR 支票處理能夠有效率地處理銀行文件。 開發人員應該選擇哪一種解決方案? Tesseract 和 IronOCR 之間的選擇取決於特定的專案要求和限制。 選擇 Tesseract 的情況: 預算限制需要免費解決方案。 專門處理影像文件 專案時間表允許進行設定故障排除。 需要客製化的OCR引擎培訓。 團隊擁有 C++ 互通經驗 需要自訂詞典 選擇 IronOCR 的情況: PDF 檔案和掃描文件是主要的輸入格式。 開發時間和程式碼簡潔性是首要考慮因素。 需要跨平台部署到 Azure、Docker 或 Linux。 內建的預處理功能將提高實際掃描的準確性 商業支援、文件和定期更新提供價值 該專案需要一些功能,例如支援多種語言或密碼保護的 PDF 處理。 您需要從掃描的紙本文件建立可搜尋的 PDF 輸出。 兩種解決方案都使用 Tesseract 的 OCR 引擎作為其光學字元辨識的核心。 然而,IronOCR 透過原生 .NET 整合、內建預處理過濾器和直接 PDF 支援擴展了其功能,解決了開發人員在生產 .NET 應用程式中實現 OCR 時遇到的常見痛點。 此授權模式包含基於使用需求的升級和擴充選項。 對於正在評估IronOCR和IronBarcode 的團隊來說,兩者的結合功能可以在一個解決方案中提供完整的文件處理能力。 .NET 開發人員的最終目標是什麼? 立即開始免費試用,評估 IronOCR 在您特定 PDF 文件上的表現,或查看生產部署的授權選項。 [{i:(Google 為各自所有者的註冊商標。 本網站與Google沒有任何關聯,也未獲得Google的認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 文中比較僅供參考,反映的是撰寫本文時公開可取得的資訊。 常見問題解答 使用 Tesseract OCR 進行 PDF 文字萃取時,主要的挑戰是什麼? 由於 Tesseract OCR 對各種 PDF 功能的支援有限,因此在處理 PDF 內容時經常會遇到挑戰,影響文字擷取的精確度和效率。 IronOCR 如何改善 PDF 中的文字擷取? IronOCR 提供將 PDF 轉換為文字的進階功能,包括對複雜文件結構的更佳支援,以及可提升 OCR 精確度與效能的整合功能。 開發人員為何在 .NET 應用程式中選擇 IronOCR 而非 Tesseract OCR? 開發人員通常會選擇 IronOCR,因為 IronOCR 易於整合到 .NET 應用程式中、可穩健處理不同的 PDF 元素,以及可靠的文字擷取結果,這些都超越了 Tesseract OCR 的能力。 IronOCR 能否有效處理掃描的文件? 是的,IronOCR 旨在高效處理掃描的文件,以高準確度將其轉換為可編輯和可搜尋的文字。 IronOCR 適用於自動化資料輸入工作流程嗎? IronOCR 非常適合用於自動化資料輸入工作流程,因為它可以快速準確地從 PDF 擷取資料,減少手動輸入並提昇效率。 哪些類型的 PDF 文件最受益於使用 IronOCR? 發票、合約和掃描紙張記錄等文件可從 IronOCR 先進的文字擷取功能中獲益良多,可輕鬆轉換成數位格式。 IronOCR 與 Tesseract OCR 等開放原始碼解決方案比較如何? 雖然 Tesseract OCR 是廣受歡迎的開放原始碼解決方案,但 IronOCR 提供更高的精確度、更好的 PDF 處理能力,以及與 C# 和 .NET 的無縫整合等強化功能,使其成為許多開發人員的首選。 IronOCR 與哪些程式設計環境相容? IronOCR 與 C# 和 .NET 環境完全相容,因此對於在這些 Framework 中工作的開發人員而言,IronOCR 是一個多功能且功能強大的工具。 IronOCR 支援可搜尋的 PDF 嗎? 是的,IronOCR 可以將掃描的 PDF 轉換成可搜尋的文件,讓使用者可以輕鬆地搜尋和瀏覽文字內容。 使用 IronOCR 進行 PDF 文本提取的主要優勢是什麼? 使用 IronOCR 的主要優勢在於它能夠準確地從複雜的 PDF 文件中抽取文字,提供可靠的結果,簡化文字轉換過程。 Kannapat Udonpant 立即與工程團隊聊天 軟體工程師 在成為軟體工程師之前,Kannapat 完成了日本北海道大學的環境資源博士學位。在攻讀學位期間,Kannapat 也成為生物製造工程系車輛機器人實驗室的成員。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程團隊,主要負責 IronPDF 的開發。Kannapat 非常重視他的工作,因為他可以直接向撰寫 IronPDF 使用的大部分程式碼的開發者學習。除了同儕學習之外,Kannapat 也很享受在 Iron Software 工作的社交生活。不寫程式碼或文件時,Kannapat 通常會用 PS5 玩遊戲或重看《最後的我們》。 相關文章 更新2026年1月5日 適用於 Windows 10 的最佳 OCR 軟體:完整比較指南 [2025] 瞭解適用於 Windows 10 的最佳 OCR 軟體。 閱讀更多 更新2026年1月5日 使用 Tesseract C# vs IronOCR:在 .NET 中實現 OCR 的完整指南 學習如何有效率地使用 Tesseract C# 和 IronOCR 進行光學字元識別。 閱讀更多 更新2026年1月5日 IronOCR vs Azure OCR PDF:哪種解決方案能更好地萃取文字? 將 Azure OCR PDF 功能與 IronOCR for .NET 進行比較。請參閱程式碼範例、定價以及擷取文字和建立可搜尋 PDF 的功能。 閱讀更多 適用於 Windows 10 的最佳 OCR 軟體:完整比較指南 [2025]使用 Tesseract C# vs IronOCR:...
更新2026年1月5日 使用 Tesseract C# vs IronOCR:在 .NET 中實現 OCR 的完整指南 學習如何有效率地使用 Tesseract C# 和 IronOCR 進行光學字元識別。 閱讀更多
更新2026年1月5日 IronOCR vs Azure OCR PDF:哪種解決方案能更好地萃取文字? 將 Azure OCR PDF 功能與 IronOCR for .NET 進行比較。請參閱程式碼範例、定價以及擷取文字和建立可搜尋 PDF 的功能。 閱讀更多