How to Use Progress Tracking

IronOCR provides an event for subscribing to track the progress of the OCR (Optical Character Recognition) reading operation. These properties offer valuable information about the progress, duration, and completion status of the OCR job, enabling applications to effectively monitor and report on the OCR process.

Get Started with IronOCR

Start using IronOCR in your project today with a free trial.

First Step:
green arrow pointer



Progress Tracking Example

The OcrProgress event can be subscribed to receive progress updates on the reading process. 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, Iowa State University.

:path=/static-assets/ocr/content-code-examples/how-to/progress-tracking-progress-tracking.cs
using IronOcr;
using System;

// Initialize the IronTesseract OCR object
var ocrTesseract = new IronTesseract();

// Subscribe to the OcrProgress event to monitor OCR progress
ocrTesseract.OcrProgress += (_, ocrProgressEventArgs) =>
{
    // Log the start time of the OCR process
    Console.WriteLine("Start time: " + ocrProgressEventArgs.StartTimeUTC.ToString());

    // Log the total number of pages that will be processed
    Console.WriteLine("Total pages number: " + ocrProgressEventArgs.TotalPages);

    // Log progress percentage and elapsed duration of the OCR process
    Console.WriteLine("Progress(%) | Duration");
    Console.WriteLine("    " + ocrProgressEventArgs.ProgressPercent + "%     | " + ocrProgressEventArgs.Duration.TotalSeconds + "s");

    // Log the end time of the OCR process, if available
    if (ocrProgressEventArgs.EndTimeUTC.HasValue)
    {
        Console.WriteLine("End time: " + ocrProgressEventArgs.EndTimeUTC.Value.ToString());
    }

    // Separator for readability
    Console.WriteLine("----------------------------------------------");
};

// Create an instance of OcrInput to process input documents
using var input = new OcrInput();

// Load the target PDF document
try
{
    input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf");
}
catch (Exception ex)
{
    Console.WriteLine("Error loading PDF: " + ex.Message);
    return;
}

// Execute the OCR read operation; progress events will be triggered during this operation
try
{
    var result = ocrTesseract.Read(input);

    // Optional: Output the OCR result (if needed)
    // Console.WriteLine(result.Text);
}
catch (Exception ex)
{
    Console.WriteLine("Error during OCR processing: " + ex.Message);
}
Imports IronOcr
Imports System

' Initialize the IronTesseract OCR object
Private ocrTesseract = New IronTesseract()

' Subscribe to the OcrProgress event to monitor OCR progress
Private ocrTesseract.OcrProgress += Sub(underscore, ocrProgressEventArgs)
	' Log the start time of the OCR process
	Console.WriteLine("Start time: " & ocrProgressEventArgs.StartTimeUTC.ToString())

	' Log the total number of pages that will be processed
	Console.WriteLine("Total pages number: " & ocrProgressEventArgs.TotalPages)

	' Log progress percentage and elapsed duration of the OCR process
	Console.WriteLine("Progress(%) | Duration")
	Console.WriteLine("    " & ocrProgressEventArgs.ProgressPercent & "%     | " & ocrProgressEventArgs.Duration.TotalSeconds & "s")

	' Log the end time of the OCR process, if available
	If ocrProgressEventArgs.EndTimeUTC.HasValue Then
		Console.WriteLine("End time: " & ocrProgressEventArgs.EndTimeUTC.Value.ToString())
	End If

	' Separator for readability
	Console.WriteLine("----------------------------------------------")
End Sub

' Create an instance of OcrInput to process input documents
Private input = New OcrInput()

' Load the target PDF document
Try
	input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf")
Catch ex As Exception
	Console.WriteLine("Error loading PDF: " & ex.Message)
	Return
End Try

' Execute the OCR read operation; progress events will be triggered during this operation
Try
	Dim result = ocrTesseract.Read(input)

	' Optional: Output the OCR result (if needed)
	' Console.WriteLine(result.Text);
Catch ex As Exception
	Console.WriteLine("Error during OCR processing: " & ex.Message)
End Try
$vbLabelText   $csharpLabel
Progress update

Information from the Event

  • ProgressPercent: Represents the progress of the OCR job as a percentage of pages completed. It ranges from 0 to 100.
  • TotalPages: Indicates the total number of pages being processed by the OCR engine.
  • PagesComplete: Specifies the number of pages where OCR reading has been fully completed. This count may increase gradually as pages are processed.
  • Duration: Represents the total duration of the OCR job, indicating the time taken for the entire process to complete. It's measured in TimeSpan format. This time is updated every time the event is triggered.
  • StartTimeUTC: Denotes the date and time when the OCR job started, represented in Coordinated Universal Time (UTC) format.
  • EndTimeUTC: Represents the date and time when the OCR job was 100% completed in UTC format. This property is null while OCR is still in progress and gets populated once the OCR process is finished.

Frequently Asked Questions

How do I start using progress tracking with IronOCR in C#?

To start using progress tracking with IronOCR, you need to download the C# library from NuGet and subscribe to the OcrProgress event to receive updates on the OCR process.

What information can be obtained from the OcrProgress event?

The OcrProgress event provides information such as the progress percentage, total pages, pages completed, elapsed time, and start time in UTC format.

How can I display the progress of the OCR process?

You can display the progress of the OCR process by subscribing to the OcrProgress event and using the eventArgs to retrieve progress details like percentage completed, pages completed, and elapsed time.

What does the ProgressPercent property represent?

The ProgressPercent property represents the progress of the OCR job as a percentage of pages completed, ranging from 0 to 100.

How is the Duration property used in progress tracking?

The Duration property indicates the total time taken for the OCR job to complete. It is updated each time the OcrProgress event is triggered.

What is the significance of StartTimeUTC in the OCR process?

StartTimeUTC denotes the date and time when the OCR job started, represented in Coordinated Universal Time (UTC). It helps track when the OCR process began.

Is it possible to track when the OCR job is completed?

Yes, the EndTimeUTC property becomes populated with the date and time in UTC format once the OCR job is 100% completed.

Can I track the number of pages processed during OCR?

Yes, the PagesComplete and TotalPages properties allow you to track the number of pages that have been fully processed and the total number of pages being processed, respectively.

What coding example is provided for progress tracking?

The provided coding example demonstrates how to subscribe to the OcrProgress event in C# to track the OCR process using a sample PDF document titled 'Experiences in Biodiversity Research: A Field Course.'

Chaknith related to Information from the Event
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.