How to Read Barcodes and QR Codes

Reading barcodes and QR codes with OCR technology can be useful in scenarios where these codes are part of printed or digital documents and need to be automatically processed. It allows for automation and data extraction from a wide range of sources, making it a versatile solution for businesses and developers.

IronOcr makes barcode and QR code detection automatic with only one additional setting needed to enable the detection.

Get started with IronOCR

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

First Step:
green arrow pointer



Read Barcode Example

Construct the IronTesseract object to perform the reading. Enable barcode reading by setting the ReadBarCodes property to true. Import the PDF document by passing it into the OcrPdfInput constructor. Then, use the Read method to perform OCR on the imported PDF document.

Now, let's perform OCR on the following PDF document:

:path=/static-assets/ocr/content-code-examples/how-to/barcodes-read-barcodes.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("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);
}
Imports IronOcr
Imports System

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Enable barcode reading
ocrTesseract.Configuration.ReadBarCodes = True

' Add PDF
Dim imageInput = New OcrPdfInput("pdfWithBarcodes.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
Reading result

As you can see, multiple barcode values that are also included in the extracted text are displayed below the barcodes.

Read QR Code Example

Similar to reading a barcode, the ReadBarCodes property must be set to true. Besides changing the file path, no other changes are necessary in the code. Now, let's perform OCR on the PDF document that has 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
Reading result

Frequently Asked Questions

How can I read barcodes and QR codes in .NET C#?

In .NET C#, you can read barcodes and QR codes using IronOCR by downloading the library from NuGet, importing the target image or PDF, enabling barcode reading with the ReadBarCodes property set to true, and using the Read method to perform OCR.

What is the process to perform OCR on documents with barcodes using IronOCR?

To perform OCR on documents with barcodes using IronOCR, construct the IronTesseract object, enable barcode reading by setting the ReadBarCodes property to true, import the document using the OcrPdfInput constructor, and use the Read method to extract text and barcode values.

Can IronOCR read both barcodes and QR codes from the same document?

Yes, IronOCR can read both barcodes and QR codes from the same document by enabling the ReadBarCodes property. The library outputs all detected text and barcode values.

How do you enable barcode reading in IronOCR?

Barcode reading in IronOCR is enabled by setting the ReadBarCodes property to true. This setting allows the library to detect and decode barcodes and QR codes from documents.

Is it necessary to change the code when switching from reading barcodes to QR codes?

No significant code changes are necessary when switching from reading barcodes to QR codes with IronOCR. The ReadBarCodes property remains the same; only the file path might need to be changed.

What types of documents can IronOCR process for barcode and QR code extraction?

IronOCR can process a variety of documents, both printed and digital, to extract barcodes and QR codes, making it suitable for automating data extraction across diverse sources.

How does IronOCR enhance automation in data processing tasks?

IronOCR enhances automation in data processing tasks by allowing developers to automatically extract and decode barcodes and QR codes from documents, streamlining workflows and improving efficiency.

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.