IRONSOFTWAREHOME

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

Curtis Chau
Curtis Chau
Updated: August 2, 2026

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.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

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

    Start using IronOCR in your project today with a free trial
    arrow pointer

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 constructor. Use the Read method to perform OCR on the imported PDF.

Here's an example using this PDF document:

using IronOcr;
using System;

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

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

// Add PDF
using var imageInput = new OcrPdfInput("pdfWithBarcodes.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);
}
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:

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);
}
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);
  3. Orientation Problems: QR codes at angles may not decode properly. Enable page rotation detection to handle misaligned documents.

  4. 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);
  2. 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($"  Format: {barcode.Format}");
        }
    }
    C#
  3. Async Processing: For better performance with multiple documents, use async methods:

    // Asynchronous QR code reading
    var result = await ocrTesseract.ReadAsync(imageInput);
  4. Debug Recognition Issues: Enable result highlighting to visualize what IronOCR detects:

    input.HighlightTextAndSaveAsImages(ocrTesseract, "qr-detection-debug.png", ResultHighlightType.Word);
    C#

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();
  2. Memory Management: Use abort tokens for long-running operations:

    // Start an async read that can be aborted if it runs too long
    OcrReadTask ocrReadTask = ocrTesseract.ReadAsync(ocrInput);
    
    // Cancel if processing takes longer than 5 minutes
    if (!ocrReadTask.Wait(TimeSpan.FromMinutes(5)))
    {
        ocrReadTask.Cancel();
    }
    C#
  3. 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");

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 can I read barcodes and QR codes in C# using IronOCR?

IronOCR can read barcodes and QR codes in C# by setting the `ReadBarCodes` property to true in the configuration. This enables the extraction of various barcode formats from PDFs and images.

What barcode formats does IronOCR support?

IronOCR supports over 20 barcode formats including 1D barcodes like Code 128, Code 39, and UPC-A, as well as 2D barcodes like QR Code, Data Matrix, and PDF417.

Why should I use IronOCR for barcode and QR code reading instead of dedicated barcode libraries?

IronOCR is beneficial when documents contain both text and barcodes, allowing you to use a single library for mixed content processing, particularly in documents such as shipping labels and invoices.

How do I enable barcode reading in IronOCR?

To enable barcode reading, create an `IronTesseract` object and set the `ReadBarCodes` property to true. Then use the `Read` method to process PDFs or images that contain barcodes.

What advantages does IronOCR's dual extraction feature offer?

IronOCR's dual extraction feature allows for simultaneous text and barcode extraction, providing comprehensive document analysis in one process.

How can I improve the accuracy of QR code recognition with IronOCR?

Improve QR code recognition by ensuring high resolution, applying image corrections like de-noising and sharpening, and handling orientation issues.

What are common challenges when reading QR codes with OCR?

Common challenges include resolution issues, image quality problems, orientation errors, and interference from overlapping text or graphics.

Can IronOCR handle multi-page PDF documents with barcodes?

Yes, IronOCR can process multi-page PDF documents with barcodes by reading each page individually and outputting detected barcode values and formats.

What is the benefit of using IronOCR for PDF text extraction and barcode reading?

Using IronOCR allows for unified text and barcode extraction from PDF documents, reducing the need for separate libraries and processing steps for each type of data.

How can IronOCR's barcode capabilities integrate into business applications?

IronOCR can be used in various business applications such as inventory management, document archiving, invoice processing, and healthcare records by extracting and processing barcode information.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required