How to use OcrProgress Tracking in C#

How to Use Progress Tracking in C# with IronOCR

IronOCR provides an event-based progress tracking system for OCR operations, allowing developers to monitor reading progress through the OcrProgress event which reports completion percentage, pages processed, and time metrics in real-time.

Quickstart: Subscribe to OcrProgress and Read PDF

This example shows how to monitor OCR progress with IronOCR: subscribe to its built-in OcrProgress event and receive instant feedback including percentage, pages completed, and total pages while reading a PDF. Only a few lines are needed to get started.

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


How Do I Implement Progress Tracking in My OCR Application?

Progress tracking is essential when processing large documents or batches of files with OCR. The OcrProgress event can be subscribed to receive progress updates on the reading process. This is particularly useful for PDF OCR operations and when working with multipage TIFF files.

The event passes 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. This functionality works seamlessly with async operations and can be combined with multithreading for enhanced performance.

The following example uses this document as a 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;

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
Console output showing progress tracking from 95% to 100% completion with timestamps and duration data

What Progress Information Can I Access from the Event?

The OcrProgress event provides comprehensive progress data that helps monitor and optimize OCR performance. Each property serves a specific purpose in tracking the operation:

  • ProgressPercent: Progress of the OCR job as a percentage of pages completed, ranging from 0 to 100. Useful for updating progress bars in GUI applications.
  • TotalPages: Total number of pages being processed by the OCR engine. Essential for calculating estimated completion times.
  • PagesComplete: Number of pages where OCR reading has been fully completed. This count increases gradually as pages are processed.
  • Duration: Total duration of the OCR job, indicating time taken for the entire process to complete. Measured in TimeSpan format and updated every time the event triggers.
  • StartTimeUTC: Date and time when the OCR job started, represented in Coordinated Universal Time (UTC) format.
  • EndTimeUTC: Date and time when the OCR job was 100% completed in UTC format. This property is null while OCR is in progress and gets populated once the process finishes.

Advanced Progress Tracking Implementation

For production applications, implement more sophisticated progress tracking. This example includes error handling and detailed logging:

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;
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Integrating Progress Tracking with UI Applications

When building desktop applications with Windows Forms or WPF, progress tracking becomes crucial for user experience. The progress event can update UI elements safely:

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");
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Working with Large Documents and Timeouts

When processing extensive documents, progress tracking becomes even more valuable. Combine it with timeout settings and abort tokens for better control:

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");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Best Practices for Progress Tracking

  1. Frequency of Updates: The OcrProgress event fires frequently during processing. Consider filtering updates to avoid overwhelming your UI or logs.

  2. Performance Impact: Progress tracking has minimal performance overhead, but excessive logging or UI updates can slow down the OCR process.

  3. Memory Management: For large TIFF files or PDFs, monitor memory usage alongside progress to ensure optimal performance.

  4. Error Handling: Always include error handling in your progress event handlers to prevent exceptions from disrupting the OCR process.

  5. Thread Safety: When updating UI elements from the progress event, ensure proper thread synchronization using Invoke or BeginInvoke methods.

Conclusion

Progress tracking in IronOCR provides essential visibility into OCR operations, enabling developers to create responsive applications that keep users informed about processing status. By leveraging the OcrProgress event effectively, you can build professional applications that handle everything from single-page documents to extensive PDF files with confidence.

For more advanced OCR techniques, explore our guides on image filters and result objects to further enhance your OCR implementations.

Frequently Asked Questions

How do I track OCR progress in real-time?

IronOCR provides an event-based progress tracking system through the OcrProgress event. Simply subscribe to this event on your IronTesseract instance, and you'll receive real-time updates including completion percentage, pages processed, and time metrics during OCR operations.

What information does the OcrProgress event provide?

The OcrProgress event in IronOCR provides comprehensive data including ProgressPercent (0-100%), TotalPages count, PagesComplete count, start and end times, and total duration. This information is particularly useful for updating progress bars in GUI applications and monitoring OCR performance.

Can I use progress tracking with async OCR operations?

Yes, IronOCR's progress tracking functionality works seamlessly with async operations. You can combine it with asynchronous processing and even multithreading to enhance performance while still receiving real-time progress updates through the OcrProgress event.

How do I implement a simple progress tracker for PDF OCR?

To implement basic progress tracking with IronOCR, create an IronTesseract instance, subscribe to the OcrProgress event with a lambda expression or event handler, then call the Read method with your PDF. The event will fire periodically, providing percentage complete and pages processed information.

Is progress tracking useful for large document processing?

Progress tracking is essential when processing large documents or batches of files with IronOCR. It's particularly valuable for PDF OCR operations and multipage TIFF files, allowing you to monitor processing status, estimate completion times, and provide user feedback during lengthy operations.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Ready to Get Started?
Nuget Downloads 5,246,844 | Version: 2025.12 just released