如何在 C# 中使用 OcrProgress 跟踪

How to Use Progress Tracking

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronOCR 提供了一個事件來訂閱追蹤 OCR(光學字元識別)讀取操作的進度。 這些屬性提供有關進度、持續時間和完成狀態的寶貴資訊,便於應用程式有效監控並報告 OCR 過程。

作為標題:2(快速入門: 訂閱 OcrProgress 並閱讀 PDF)

這個範例說明了如何輕鬆使用 IronOCR 監控 OCR 進度:訂閱其內建的OcrProgress事件以獲取即時反饋(百分比、已完成頁數、總頁數),在讀取 PDF 時。 只需幾行即可開始。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    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"));
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小化工作流程(5 步驟)

  1. 下載一個 C# 庫以追蹤閱讀進度
  2. 訂閱OcrProgress事件
  3. 利用事件傳遞的實例來檢索進度資訊
  4. 以百分比和總持續時間獲取進度
  5. 檢索開始和結束時間,以及總頁數


進度追蹤範例

OcrProgress事件可以被訂閱以接收閱讀過程的進度更新。 The event will pass an instance containing information about the progress of the OCR job, such as the start time, total pages, progress as a percentage, duration, and end time. Let's use the following document as our sample: "Experiences in Biodiversity Research: A Field Course" by Thea B. Gessler,愛荷華州立大學。

: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
class="content-img-align-center">
class="center-image-wrapper"> 進度更新

事件中的資訊

  • ProgressPercent: 表示 OCR 工作的進度,以完成的頁數百分比表示。 範圍從 0 到 100。
  • TotalPages: 表示 OCR 引擎正在處理的總頁數。
  • PagesComplete: 指定 OCR 讀取已完全完成的頁數。 此失計可隨頁數處理而逐漸增加。
  • Duration: 表示 OCR 工作的總持續時間,指整個過程完成所需的時間。 其以 TimeSpan 格式測量。 每次事件觸發時,此時間將更新。
  • StartTimeUTC: 表示 OCR 工作開始的日期和時間,並以協調世界時(UTC)格式表示。
  • EndTimeUTC: 表示 OCR 工作 100% 完成的日期和時間,以 UTC 格式表示。 此屬性在 OCR 進行中時為空,並在 OCR 過程完成後填充。

常見問題解答

如何在 C# 中追蹤 OCR 作業的進度?

您可以透過訂閱 IronOCR 中的OcrProgress事件來追蹤 C# 中 OCR 作業的進度。此事件會提供有關完成百分比、持續時間和已處理頁數的更新資訊。

OcrProgress事件在 OCR 操作中扮演什麼角色?

IronOCR 中的OcrProgress事件允許開發人員接收有關 OCR 作業狀態的即時更新,包括進度百分比、總持續時間、開始和結束時間以及正在處理的總頁數。

ProgressPercent屬性提供哪些資訊?

IronOCR 中的ProgressPercent屬性以百分比形式指示 OCR 作業的進度,清楚顯示任務的完成情況,範圍從 0 到 100。

如何取得OCR製程的總時長?

您可以透過存取 IronOCR 中的Duration屬性來取得 OCR 過程的總持續時間,該屬性會在每次觸發OcrProgress事件時更新,反映整個過程所花費的時間。

我可以確定 OCR 作業的開始和結束時間嗎?

是的,IronOCR 提供了StartTimeUTCEndTimeUTC屬性,分別表示 OCR 作業的開始時間和完成時間(UTC 格式)。

如何在OCR處理過程中處理多頁內容?

在 IronOCR 中,您可以使用TotalPagesPagesComplete屬性來追蹤正在處理的頁面總數和完全處理的頁面數,從而處理多個頁面。

在OCR中,進度追蹤的實際應用範例是什麼?

一個實際的例子是,在處理名為「生物多樣性研究經驗:實地課程」的範例文件時訂閱OcrProgress事件。這演示瞭如何在 IronOCR 中追蹤進度、持續時間和完成狀態。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布