IronOCR 操作指南 進度追踪 如何使用 IronOCR 在 C# 中使用進度追蹤。 Curtis Chau 更新:2026年1月10日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronOCR 為 OCR 作業提供了一個以事件為基礎的進度追蹤系統,讓開發人員可以透過 OcrProgress 事件來監控閱讀進度,該事件會即時報告完成百分比、處理的頁面以及時間指標。 <! -- --> <!--說明:說明程式碼概念的圖表或截圖 --> 快速入門:訂閱 OcrProgress 並閱讀 PDF 本範例展示如何使用 IronOCR 監控 OCR 進度:訂閱其內建的 OcrProgress 事件,並在閱讀 PDF 時接收即時回饋,包括百分比、已完成頁數和總頁數。 只需要幾行就可以開始。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronOCR PM > Install-Package IronOcr 複製並運行這段程式碼。 var ocr = new IronOcr.IronTesseract(); ocr.OcrProgress += (s, e) => Console.WriteLine(e.ProgressPercent + "% (" + e.PagesComplete + "/" + e.TotalPages + ")"); var result = ocr.Read(new IronOcr.OcrInput().LoadPdf("file.pdf")); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronOCR,免費試用! 免費試用30天 ### 最小工作流程(5 個步驟) 下載一個用於追蹤閱讀進度的 C# 庫 訂閱OcrProgress活動 利用事件傳遞的實例來獲取進度信息 獲得百分比進度和總時長 取得開始時間和結束時間,以及總頁數 如何在我的 OCR 應用程式中實作進度追蹤? <! -- --> <!--說明:說明程式碼概念的圖表或截圖 --> 使用 OCR 處理大型文件或批次文件時,進度追蹤是不可或缺的。 訂閱OcrProgress事件即可接收閱讀過程的進度更新。 這對於 PDF OCR 作業以及處理 多頁 TIFF 檔案時特別有用。 事件傳遞一個包含 OCR 工作進度資訊的實例,例如開始時間、總頁數、進度百分比、持續時間和結束時間。此功能可與async作業無縫運作,並可結合多執行緒以增強效能。 The following example uses this document as a sample: "Experiences in Biodiversity Research: A Field Course" by Thea B. 蓋斯勒,愛荷華州立大學。 :path=/static-assets/ocr/content-code-examples/how-to/progress-tracking-progress-tracking.cs using IronOcr; using System; var ocrTesseract = new IronTesseract(); // Subscribe to OcrProgress event ocrTesseract.OcrProgress += (_, ocrProgressEventsArgs) => { Console.WriteLine("Start time: " + ocrProgressEventsArgs.StartTimeUTC.ToString()); Console.WriteLine("Total pages number: " + ocrProgressEventsArgs.TotalPages); Console.WriteLine("Progress(%) | Duration"); Console.WriteLine(" " + ocrProgressEventsArgs.ProgressPercent + "% | " + ocrProgressEventsArgs.Duration.TotalSeconds + "s"); Console.WriteLine("End time: " + ocrProgressEventsArgs.EndTimeUTC.ToString()); Console.WriteLine("----------------------------------------------"); }; using var input = new OcrInput(); input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf"); // Progress events will fire during the read operation var result = ocrTesseract.Read(input); Imports IronOcr Imports System Private ocrTesseract = New IronTesseract() ' Subscribe to OcrProgress event Private ocrTesseract.OcrProgress += Sub(underscore, ocrProgressEventsArgs) Console.WriteLine("Start time: " & ocrProgressEventsArgs.StartTimeUTC.ToString()) Console.WriteLine("Total pages number: " & ocrProgressEventsArgs.TotalPages) Console.WriteLine("Progress(%) | Duration") Console.WriteLine(" " & ocrProgressEventsArgs.ProgressPercent & "% | " & ocrProgressEventsArgs.Duration.TotalSeconds & "s") Console.WriteLine("End time: " & ocrProgressEventsArgs.EndTimeUTC.ToString()) Console.WriteLine("----------------------------------------------") End Sub Private input = New OcrInput() input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf") ' Progress events will fire during the read operation Dim result = ocrTesseract.Read(input) $vbLabelText $csharpLabel 我可以從活動中取得哪些進度資訊? OcrProgress 事件提供全面的進度資料,有助於監控和最佳化 OCR 效能。 每個屬性都有追蹤作業的特定目的: ProgressPercent:OCR 工作的進度,以完成頁數的百分比表示,範圍從 0 到 100。對於更新 GUI 應用程式中的進度列非常有用。 TotalPages: OCR 引擎正在處理的總頁數。對於計算預計完成時間來說非常重要。 PagesComplete:已完全完成 OCR 讀取的頁數。 此數量會隨著頁面的處理而逐漸增加。 持續時間:OCR 工作的總持續時間,表示整個流程完成所需的時間。 以 TimeSpan 格式測量,並在每次事件觸發時更新。 StartTimeUTC:OCR 工作開始的日期和時間,以 Coordinated Universal Time (UTC) 格式表示。 EndTimeUTC:OCR 工作 100% 完成的日期和時間,以 UTC 格式表示。 此屬性在 OCR 進行中時為空,並在過程結束後填入。 進階進度追蹤實作 針對生產應用程式,實施更精密的進度追蹤。 本範例包括錯誤處理和詳細記錄: using IronOcr; using System; using System.Diagnostics; public class OcrProgressTracker { private readonly IronTesseract _tesseract; private Stopwatch _stopwatch; private int _lastReportedPercent = 0; public OcrProgressTracker() { _tesseract = new IronTesseract(); // Configure for optimal performance _tesseract.Language = OcrLanguage.EnglishBest; _tesseract.Configuration.ReadBarCodes = false; // Subscribe to progress event _tesseract.OcrProgress += OnOcrProgress; } private void OnOcrProgress(object sender, OcrProgressEventsArgs e) { // Only report significant progress changes (every 10%) if (e.ProgressPercent - _lastReportedPercent >= 10 || e.ProgressPercent == 100) { _lastReportedPercent = e.ProgressPercent; Console.WriteLine($"Progress: {e.ProgressPercent}%"); Console.WriteLine($"Pages: {e.PagesComplete}/{e.TotalPages}"); Console.WriteLine($"Elapsed: {e.Duration.TotalSeconds:F1}s"); // Estimate remaining time if (e.ProgressPercent > 0 && e.ProgressPercent < 100) { var estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0); var remaining = estimatedTotal - e.Duration.TotalSeconds; Console.WriteLine($"Estimated remaining: {remaining:F1}s"); } Console.WriteLine("---"); } } public OcrResult ProcessDocument(string filePath) { _stopwatch = Stopwatch.StartNew(); using var input = new OcrInput(); input.LoadPdf(filePath); // Apply image filters for better accuracy input.Deskew(); input.DeNoise(); var result = _tesseract.Read(input); _stopwatch.Stop(); Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s"); return result; } } using IronOcr; using System; using System.Diagnostics; public class OcrProgressTracker { private readonly IronTesseract _tesseract; private Stopwatch _stopwatch; private int _lastReportedPercent = 0; public OcrProgressTracker() { _tesseract = new IronTesseract(); // Configure for optimal performance _tesseract.Language = OcrLanguage.EnglishBest; _tesseract.Configuration.ReadBarCodes = false; // Subscribe to progress event _tesseract.OcrProgress += OnOcrProgress; } private void OnOcrProgress(object sender, OcrProgressEventsArgs e) { // Only report significant progress changes (every 10%) if (e.ProgressPercent - _lastReportedPercent >= 10 || e.ProgressPercent == 100) { _lastReportedPercent = e.ProgressPercent; Console.WriteLine($"Progress: {e.ProgressPercent}%"); Console.WriteLine($"Pages: {e.PagesComplete}/{e.TotalPages}"); Console.WriteLine($"Elapsed: {e.Duration.TotalSeconds:F1}s"); // Estimate remaining time if (e.ProgressPercent > 0 && e.ProgressPercent < 100) { var estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0); var remaining = estimatedTotal - e.Duration.TotalSeconds; Console.WriteLine($"Estimated remaining: {remaining:F1}s"); } Console.WriteLine("---"); } } public OcrResult ProcessDocument(string filePath) { _stopwatch = Stopwatch.StartNew(); using var input = new OcrInput(); input.LoadPdf(filePath); // Apply image filters for better accuracy input.Deskew(); input.DeNoise(); var result = _tesseract.Read(input); _stopwatch.Stop(); Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s"); return result; } } Imports IronOcr Imports System Imports System.Diagnostics Public Class OcrProgressTracker Private ReadOnly _tesseract As IronTesseract Private _stopwatch As Stopwatch Private _lastReportedPercent As Integer = 0 Public Sub New() _tesseract = New IronTesseract() ' Configure for optimal performance _tesseract.Language = OcrLanguage.EnglishBest _tesseract.Configuration.ReadBarCodes = False ' Subscribe to progress event AddHandler _tesseract.OcrProgress, AddressOf OnOcrProgress End Sub Private Sub OnOcrProgress(sender As Object, e As OcrProgressEventsArgs) ' Only report significant progress changes (every 10%) If e.ProgressPercent - _lastReportedPercent >= 10 OrElse e.ProgressPercent = 100 Then _lastReportedPercent = e.ProgressPercent Console.WriteLine($"Progress: {e.ProgressPercent}%") Console.WriteLine($"Pages: {e.PagesComplete}/{e.TotalPages}") Console.WriteLine($"Elapsed: {e.Duration.TotalSeconds:F1}s") ' Estimate remaining time If e.ProgressPercent > 0 AndAlso e.ProgressPercent < 100 Then Dim estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0) Dim remaining = estimatedTotal - e.Duration.TotalSeconds Console.WriteLine($"Estimated remaining: {remaining:F1}s") End If Console.WriteLine("---") End If End Sub Public Function ProcessDocument(filePath As String) As OcrResult _stopwatch = Stopwatch.StartNew() Using input As New OcrInput() input.LoadPdf(filePath) ' Apply image filters for better accuracy input.Deskew() input.DeNoise() Dim result = _tesseract.Read(input) _stopwatch.Stop() Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s") Return result End Using End Function End Class $vbLabelText $csharpLabel 整合進度追蹤與 UI 應用程式。 當使用 Windows Forms 或 WPF 建立桌面應用程式時,進度追蹤對使用者體驗非常重要。 進度事件可以安全地更新 UI 元素: using System; using System.Windows.Forms; using IronOcr; public partial class OcrForm : Form { private IronTesseract _tesseract; private ProgressBar progressBar; private Label statusLabel; public OcrForm() { InitializeComponent(); _tesseract = new IronTesseract(); _tesseract.OcrProgress += UpdateProgress; } private void UpdateProgress(object sender, OcrProgressEventsArgs e) { // Ensure UI updates happen on the main thread if (InvokeRequired) { BeginInvoke(new Action(() => UpdateProgress(sender, e))); return; } progressBar.Value = e.ProgressPercent; statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}"; // Show completion message if (e.ProgressPercent == 100) { MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds"); } } } using System; using System.Windows.Forms; using IronOcr; public partial class OcrForm : Form { private IronTesseract _tesseract; private ProgressBar progressBar; private Label statusLabel; public OcrForm() { InitializeComponent(); _tesseract = new IronTesseract(); _tesseract.OcrProgress += UpdateProgress; } private void UpdateProgress(object sender, OcrProgressEventsArgs e) { // Ensure UI updates happen on the main thread if (InvokeRequired) { BeginInvoke(new Action(() => UpdateProgress(sender, e))); return; } progressBar.Value = e.ProgressPercent; statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}"; // Show completion message if (e.ProgressPercent == 100) { MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds"); } } } Imports System Imports System.Windows.Forms Imports IronOcr Public Partial Class OcrForm Inherits Form Private _tesseract As IronTesseract Private progressBar As ProgressBar Private statusLabel As Label Public Sub New() InitializeComponent() _tesseract = New IronTesseract() AddHandler _tesseract.OcrProgress, AddressOf UpdateProgress End Sub Private Sub UpdateProgress(sender As Object, e As OcrProgressEventsArgs) ' Ensure UI updates happen on the main thread If InvokeRequired Then BeginInvoke(New Action(Sub() UpdateProgress(sender, e))) Return End If progressBar.Value = e.ProgressPercent statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}" ' Show completion message If e.ProgressPercent = 100 Then MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds") End If End Sub End Class $vbLabelText $csharpLabel 處理大型文件和超時問題 在處理大量文件時,進度追蹤變得更有價值。 結合逾時設定和中止令牌,以達到更好的控制效果: using IronOcr; using System; using System.Threading; public async Task ProcessLargeDocumentWithTimeout() { var cts = new CancellationTokenSource(); var tesseract = new IronTesseract(); // Set a timeout of 5 minutes cts.CancelAfter(TimeSpan.FromMinutes(5)); tesseract.OcrProgress += (s, e) => { Console.WriteLine($"Progress: {e.ProgressPercent}% - Page {e.PagesComplete}/{e.TotalPages}"); // Check if we should cancel based on progress if (e.Duration.TotalMinutes > 4 && e.ProgressPercent < 50) { Console.WriteLine("Processing too slow, cancelling..."); cts.Cancel(); } }; try { using var input = new OcrInput(); input.LoadPdf("large-document.pdf"); var result = await Task.Run(() => tesseract.Read(input, cts.Token), cts.Token); Console.WriteLine("OCR completed successfully"); } catch (OperationCanceledException) { Console.WriteLine("OCR operation was cancelled"); } } using IronOcr; using System; using System.Threading; public async Task ProcessLargeDocumentWithTimeout() { var cts = new CancellationTokenSource(); var tesseract = new IronTesseract(); // Set a timeout of 5 minutes cts.CancelAfter(TimeSpan.FromMinutes(5)); tesseract.OcrProgress += (s, e) => { Console.WriteLine($"Progress: {e.ProgressPercent}% - Page {e.PagesComplete}/{e.TotalPages}"); // Check if we should cancel based on progress if (e.Duration.TotalMinutes > 4 && e.ProgressPercent < 50) { Console.WriteLine("Processing too slow, cancelling..."); cts.Cancel(); } }; try { using var input = new OcrInput(); input.LoadPdf("large-document.pdf"); var result = await Task.Run(() => tesseract.Read(input, cts.Token), cts.Token); Console.WriteLine("OCR completed successfully"); } catch (OperationCanceledException) { Console.WriteLine("OCR operation was cancelled"); } } Imports IronOcr Imports System Imports System.Threading Imports System.Threading.Tasks Public Async Function ProcessLargeDocumentWithTimeout() As Task Dim cts As New CancellationTokenSource() Dim tesseract As New IronTesseract() ' Set a timeout of 5 minutes cts.CancelAfter(TimeSpan.FromMinutes(5)) AddHandler tesseract.OcrProgress, Sub(s, e) Console.WriteLine($"Progress: {e.ProgressPercent}% - Page {e.PagesComplete}/{e.TotalPages}") ' Check if we should cancel based on progress If e.Duration.TotalMinutes > 4 AndAlso e.ProgressPercent < 50 Then Console.WriteLine("Processing too slow, cancelling...") cts.Cancel() End If End Sub Try Using input As New OcrInput() input.LoadPdf("large-document.pdf") Dim result = Await Task.Run(Function() tesseract.Read(input, cts.Token), cts.Token) Console.WriteLine("OCR completed successfully") End Using Catch ex As OperationCanceledException Console.WriteLine("OCR operation was cancelled") End Try End Function $vbLabelText $csharpLabel 進度追蹤的最佳實務 1.更新頻率:在處理過程中,OcrProgress 事件會頻繁發生。 請考慮過濾更新內容,以免 UI 或日誌不堪負荷。 2.效能影響:進度追蹤的效能開銷極小,但過度的日誌記錄或 UI 更新可能會導致 OCR 過程變慢。 3.記憶體管理:對於大型 TIFF 檔案或 PDF,請隨著進度監控記憶體使用量,以確保最佳效能。 4.錯誤處理:務必在您的進度事件處理器中包含錯誤處理,以防止異常打亂 OCR 程序。 5.線程安全:從進度事件更新 UI 元素時,請使用 Invoke 或 BeginInvoke 方法確保適當的線程同步。 結論 IronOCR 中的進度追蹤可提供 OCR 作業的基本可見性,讓開發人員能夠建立反應迅速的應用程式,讓使用者隨時瞭解處理狀態。 透過有效地利用 OcrProgress 事件,您可以建立專業的應用程式,自信地處理從單頁文件到廣泛 PDF 檔案的一切內容。 如需更進階的 OCR 技術,請參閱我們關於 影像篩選器 和 結果物件 的指南,以進一步強化您的 OCR 實作。 常見問題解答 如何即時追蹤 OCR 的進度? IronOCR 透過 OcrProgress 事件提供以事件為基礎的進度追蹤系統。只需在您的 IronTesseract 實例上訂閱這個事件,您就能在 OCR 作業期間收到即時更新,包括完成百分比、處理的頁面以及時間指標。 OcrProgress 活動提供哪些資訊? IronOCR 中的 OcrProgress 事件提供全面的資料,包括 ProgressPercent (0-100%)、TotalPages 計數、PagesComplete 計數、開始和結束時間,以及總持續時間。這些資訊對於更新 GUI 應用程式中的進度列以及監控 OCR 效能特別有用。 我可以在進行非同步 OCR 作業時使用進度追蹤嗎? 是的,IronOCR 的進度追蹤功能可與異步作業無縫配合。您可以將其與異步處理甚至多執行緒結合,以提升效能,同時仍可透過 OcrProgress 事件接收即時進度更新。 如何為 PDF OCR 實作一個簡單的進度追蹤器? 若要使用 IronOCR 實作基本的進度追蹤,請建立一個 IronTesseract 範例,使用 lambda 表達式或事件處理程式訂閱 OcrProgress 事件,然後以 PDF 來呼叫 Read 方法。該事件會定期啟動,提供完成百分比和已處理頁數的資訊。 進度追蹤對大型文件處理有用嗎? 在使用 IronOCR 處理大型文件或批次文件時,進度追蹤是必不可少的。它對 PDF OCR 作業和多頁 TIFF 檔案尤其重要,可讓您監控處理狀態、估計完成時間,並在冗長的作業過程中提供使用者回饋。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 準備好開始了嗎? Nuget 下載 5,384,824 | 版本: 2026.2 剛剛發布 免費 NuGet 下載 總下載量:5,384,824 查看許可證