How to Read Barcodes and QR Codes Using OCR in C#

How to Read Barcodes and QR Codes in C# with IronOCR

IronOCR reads barcodes and QR codes in C# by setting ReadBarCodes = true in the configuration. This single setting enables automatic extraction of barcode values from PDFs and images alongside regular text recognition, supporting over 20 barcode formats including QR codes, Code 128, and Data Matrix.

Quickstart: Read Barcodes from a PDF Instantly

Enable barcode detection with one setting and scan PDFs with IronOCR. The code below shows how to turn on barcode reading, process a PDF, and retrieve decoded values.

```cs:title=Try IronOCR's Barcode Reader Now var result = new IronOcr.IronTesseract() { Configuration = new IronOcr.TesseractConfiguration { ReadBarCodes = true } }.Read(new IronOcr.OcrPdfInput("document.pdf")); foreach(var bc in result.Barcodes) Console.WriteLine(bc.Value);


<div class="hsg-featured-snippet">
    <h3>Minimal Workflow (5 steps)</h3>
    <ol>
        <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronOcr/">Download a C# library to read barcodes and QR codes.</a></li>
        <li>Import the target image and PDF document.</li>
        <li>Enable barcode reading by setting the <strong><code>ReadBarCodes</code></strong> property to true.</li>
        <li>Use the <code>Read</code> method to perform OCR as usual.</li>
        <li>Output the detected text and barcode values.</li>
    </ol>
</div>

<br class="clear">

## How Do I Read Barcodes from PDF Documents?

Create an `IronTesseract` object to perform the reading. Set the **`ReadBarCodes`** property to true to enable barcode detection. Import the PDF document using the [`OcrPdfInput`](https://ironsoftware.com/csharp/ocr/how-to/input-pdfs/) constructor. Use the ``Read`` method to perform OCR on the imported PDF.

Here's an example using this PDF document:

<iframe loading="lazy" src="/static-assets/ocr/how-to/barcodes/pdfWithBarcodes.pdf#view=fit" width="100%" height="400px"></iframe>

```csharp
:path=/static-assets/ocr/content-code-examples/how-to/barcodes-read-barcodes.cs
IronOCR debug output showing extracted text and three barcodes (A,B,C) from PDF with business profiles

Multiple barcode values appear below the barcodes and are included in the extracted text.

Why Does IronOCR Extract Both Text and Barcode Values?

IronOCR's dual extraction provides comprehensive document analysis. When processing documents containing both text and barcodes, the library performs standard OCR text extraction while simultaneously decoding barcode symbologies. This unified approach eliminates the need for multiple processing passes or separate libraries.

The text extraction captures human-readable elements, while barcode detection identifies and decodes machine-readable data. This benefits documents like invoices, shipping labels, or inventory reports where barcode values correlate with printed text. The OcrResult class separates these outputs—access text through the Text property and barcode data through the Barcodes collection.

What Barcode Formats Are Supported?

IronOCR supports over 20 barcode formats:

1D Barcodes:

  • Code 128, Code 39, Code 93
  • EAN-13, EAN-8
  • UPC-A, UPC-E
  • Codabar
  • ITF (Interleaved 2 of 5)
  • MSI
  • Plessey

2D Barcodes:

  • QR Code
  • Data Matrix
  • PDF417
  • Aztec Code
  • MaxiCode

For specialized applications like reading MICR cheques or processing identity documents, IronOCR's barcode capabilities complement its text extraction features.

When Should I Use OCR for Barcode Reading Instead of Dedicated Barcode Libraries?

Choose IronOCR's integrated barcode reading when:

  1. Mixed Content Processing: Documents contain both text and barcodes (shipping labels, invoices, or scanned documents)
  2. Single Library Preference: You want to minimize dependencies and use one solution
  3. PDF Processing: You're already using IronOCR for PDF OCR text extraction
  4. Complex Document Layouts: Documents have barcodes embedded within text regions or tables

Use dedicated barcode libraries when:

  • Processing high-volume barcode-only images
  • Requiring real-time barcode scanning (< 50ms response time)
  • Working with damaged or low-quality barcodes requiring specialized algorithms
  • Implementing mobile barcode scanning with camera optimization

How Do I Read QR Codes from Documents?

Like barcode reading, set the ReadBarCodes property to true. No other code changes are necessary besides the file path. Process this PDF document with QR codes:

:path=/static-assets/ocr/content-code-examples/how-to/barcodes-read-qr-codes.cs
using IronOcr;
using System;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Enable barcode reading
ocrTesseract.Configuration.ReadBarCodes = true;

// Add PDF
using var imageInput = new OcrPdfInput("pdfWithQrCodes.pdf");

// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Output detected barcodes and text values
Console.WriteLine("Extracted text:");
Console.WriteLine(ocrResult.Text);
Console.WriteLine("Extracted barcodes:");
foreach (var barcode in ocrResult.Barcodes)
{
    Console.WriteLine(barcode.Value);
}
Imports IronOcr
Imports System

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Enable barcode reading
ocrTesseract.Configuration.ReadBarCodes = True

' Add PDF
Dim imageInput = New OcrPdfInput("pdfWithQrCodes.pdf")

' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)

' Output detected barcodes and text values
Console.WriteLine("Extracted text:")
Console.WriteLine(ocrResult.Text)
Console.WriteLine("Extracted barcodes:")
For Each barcode In ocrResult.Barcodes
	Console.WriteLine(barcode.Value)
Next barcode
$vbLabelText   $csharpLabel
IronOCR output in Visual Studio showing extracted text and successfully decoded QR codes A, B, and C from document

Why Does the Same Configuration Work for Both Barcodes and QR Codes?

IronOCR's unified barcode detection engine treats all machine-readable codes equally. The ReadBarCodes configuration activates a comprehensive symbology detector that recognizes both 1D (linear barcodes) and 2D (QR codes, Data Matrix) formats without requiring format-specific settings. This design simplifies implementation and reduces configuration complexity.

The detection algorithm automatically:

  • Identifies symbology type based on pattern recognition
  • Applies appropriate decoding algorithms
  • Handles orientation and size variations
  • Returns results in a consistent format regardless of barcode type

This approach mirrors how Computer Vision models work—training on multiple formats to provide universal detection capabilities.

What Are Common Issues When Reading QR Codes with OCR?

Common challenges when processing QR codes include:

  1. Resolution Issues: QR codes in PDFs may be downsampled below the minimum module size. Use DPI settings to ensure adequate resolution (300 DPI minimum recommended).

  2. Image Quality: Scanned QR codes often suffer from blur, noise, or distortion. Apply image correction filters to enhance clarity:
// Apply filters to improve QR code readability
ocrTesseract.Configuration.ReadBarCodes = true;
var input = new OcrImageInput("qr-code-scan.jpg");
input.DeNoise();
input.Sharpen();
input.EnhanceResolution();

var result = ocrTesseract.Read(input);
// Apply filters to improve QR code readability
ocrTesseract.Configuration.ReadBarCodes = true;
var input = new OcrImageInput("qr-code-scan.jpg");
input.DeNoise();
input.Sharpen();
input.EnhanceResolution();

var result = ocrTesseract.Read(input);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Orientation Problems: QR codes at angles may not decode properly. Enable page rotation detection to handle misaligned documents.

  2. Mixed Content Interference: Text or graphics overlapping QR codes can prevent detection. Use crop regions to isolate QR code areas when necessary.

How Can I Improve QR Code Recognition Accuracy?

Optimize QR code recognition with these techniques:

  1. Pre-process Images: Use the Filter Wizard to determine optimal enhancement settings:
// Enhanced QR code reading with preprocessing
var ocrTesseract = new IronTesseract();
ocrTesseract.Configuration.ReadBarCodes = true;

// Configure for better QR detection
var input = new OcrImageInput("document-with-qr.pdf");
input.TargetDPI = 300; // Ensure sufficient resolution
input.Binarize(); // Convert to black and white
input.DeNoise(); // Remove image artifacts

var result = ocrTesseract.Read(input);
// Enhanced QR code reading with preprocessing
var ocrTesseract = new IronTesseract();
ocrTesseract.Configuration.ReadBarCodes = true;

// Configure for better QR detection
var input = new OcrImageInput("document-with-qr.pdf");
input.TargetDPI = 300; // Ensure sufficient resolution
input.Binarize(); // Convert to black and white
input.DeNoise(); // Remove image artifacts

var result = ocrTesseract.Read(input);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Handle Multiple Pages: For multi-page documents with QR codes across multiple pages:
// Process multi-page documents efficiently
using var pdfInput = new OcrPdfInput("multi-page-qr-document.pdf");
pdfInput.TargetDPI = 300;

var results = ocrTesseract.Read(pdfInput);
foreach (var page in results.Pages)
{
    Console.WriteLine($"Page {page.PageNumber}:");
    foreach (var barcode in page.Barcodes)
    {
        Console.WriteLine($"  QR Code: {barcode.Value}");
        Console.WriteLine($"  Location: X={barcode.X}, Y={barcode.Y}");
    }
}
// Process multi-page documents efficiently
using var pdfInput = new OcrPdfInput("multi-page-qr-document.pdf");
pdfInput.TargetDPI = 300;

var results = ocrTesseract.Read(pdfInput);
foreach (var page in results.Pages)
{
    Console.WriteLine($"Page {page.PageNumber}:");
    foreach (var barcode in page.Barcodes)
    {
        Console.WriteLine($"  QR Code: {barcode.Value}");
        Console.WriteLine($"  Location: X={barcode.X}, Y={barcode.Y}");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Async Processing: For better performance with multiple documents, use async methods:
// Asynchronous QR code reading
var result = await ocrTesseract.ReadAsync(imageInput);
// Asynchronous QR code reading
var result = await ocrTesseract.ReadAsync(imageInput);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Debug Recognition Issues: Enable result highlighting to visualize what IronOCR detects:
result.SaveAsHighlightedImage("qr-detection-debug.png");
result.SaveAsHighlightedImage("qr-detection-debug.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Performance Optimization for Large-Scale Barcode Processing

When processing thousands of documents with barcodes and QR codes, implement these optimization strategies:

  1. Multithreading: Leverage multithreaded processing to handle multiple documents simultaneously:
// Process multiple documents in parallel
var documents = new[] { "doc1.pdf", "doc2.pdf", "doc3.pdf" };
var results = documents.AsParallel().Select(doc =>
{
    var tesseract = new IronTesseract();
    tesseract.Configuration.ReadBarCodes = true;
    return tesseract.Read(new OcrPdfInput(doc));
}).ToList();
// Process multiple documents in parallel
var documents = new[] { "doc1.pdf", "doc2.pdf", "doc3.pdf" };
var results = documents.AsParallel().Select(doc =>
{
    var tesseract = new IronTesseract();
    tesseract.Configuration.ReadBarCodes = true;
    return tesseract.Read(new OcrPdfInput(doc));
}).ToList();
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Memory Management: Use abort tokens for long-running operations:
// Implement cancellation for large batch processing
using var cts = new CancellationTokenSource();
ocrTesseract.Configuration.CancellationToken = cts.Token;

// Cancel if processing takes too long
cts.CancelAfter(TimeSpan.FromMinutes(5));
// Implement cancellation for large batch processing
using var cts = new CancellationTokenSource();
ocrTesseract.Configuration.CancellationToken = cts.Token;

// Cancel if processing takes too long
cts.CancelAfter(TimeSpan.FromMinutes(5));
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
  1. Result Export: Save results as searchable PDFs to maintain both text and barcode data:
// Export results with embedded barcode values
result.SaveAsSearchablePdf("output-with-barcodes.pdf");
// Export results with embedded barcode values
result.SaveAsSearchablePdf("output-with-barcodes.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Integration with Business Applications

IronOCR's barcode capabilities integrate seamlessly with existing .NET applications. Common integration scenarios include:

  • Inventory Management: Extract product codes from shipping manifests
  • Document Archival: Index scanned documents by embedded barcode identifiers
  • Invoice Processing: Match barcode SKUs with line items in financial documents
  • Healthcare Records: Process patient wristband barcodes alongside medical forms

For production applications processing high volumes of barcodes and QR codes, consider implementing progress tracking to monitor processing status and optimize performance based on real-world metrics.

Frequently Asked Questions

How do I enable barcode reading in my C# application?

With IronOCR, enable barcode reading by setting ReadBarCodes = true in the TesseractConfiguration. This single setting activates automatic extraction of barcode values from PDFs and images alongside regular text recognition, supporting over 20 barcode formats.

Can I read both text and barcodes from the same document?

Yes, IronOCR performs dual extraction - it captures human-readable text through standard OCR while simultaneously decoding machine-readable barcodes. The OcrResult class separates these outputs with text accessible through the Text property and barcode data through the Barcodes collection.

What barcode formats can be detected?

IronOCR supports over 20 barcode formats including 1D barcodes (Code 128, Code 39, Code 93, EAN-13, EAN-8, UPC-A, UPC-E, Codabar, ITF, MSI, Plessey) and 2D barcodes (QR Code, Data Matrix, and more).

How do I extract barcodes from PDF documents?

Create an IronTesseract object, set ReadBarCodes to true, import your PDF using OcrPdfInput constructor, then use the Read method. IronOCR will perform OCR and extract all detected barcode values which you can access through the result.Barcodes collection.

Do I need separate libraries for text OCR and barcode reading?

No, IronOCR's unified approach eliminates the need for multiple processing passes or separate libraries. It performs standard OCR text extraction while simultaneously decoding barcode symbologies in a single operation.

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