Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we delve into the process of reading barcodes and QR codes from PDF documents using Iron OCR in C#. The tutorial begins with the installation of Iron OCR in the project using a package manager. We then proceed to import Iron OCR and set up the necessary configurations, including the license key, to unlock the library's full features. The tutorial explains how to initialize the Iron Tesseract OCR engine and configure it to read barcodes using the OCR PDF input class. By loading a PDF document containing barcodes, the OCR extracts and prints the barcode data in the console. Similarly, the tutorial covers the extraction of QR codes from another PDF document. The step-by-step guide illustrates how Iron OCR simplifies the integration of barcode and QR code reading functionalities into C# applications. The tutorial concludes by encouraging developers to explore the capabilities of Iron OCR by signing up for a trial and downloading the package. This resource is ideal for developers seeking to enhance their applications with robust code reading features.
// This code sample demonstrates the process of installing and using Iron OCR to read barcodes and QR codes from PDFs in C#.
// First, install Iron OCR via NuGet Package Manager:
// Use the Package Manager Console and run the following command:
// Install-Package IronOcr
// Import the IronOCR namespace
using IronOcr;
class Program
{
static void Main()
{
// Set the license key for Iron OCR
var Ocr = new IronTesseract();
// Initialize the OCR engine
// Setting the language to English
Ocr.Language = OcrLanguage.English;
// Load a PDF document and automatically recognize all barcodes and QR codes
using (var input = new OcrInput())
{
// Load the PDF with the path to the document containing barcodes
input.AddPdf("path_to_barcode_pdf.pdf");
// Extract barcode content
var results = Ocr.Read(input);
// Print all recognized barcode and QR code data
foreach (var barcode in results.Barcodes)
{
Console.WriteLine($"Type: {barcode.Type}, Value: {barcode.Value}");
}
}
// Similarly, to extract QR codes from another PDF document, perform the following:
using (var qrInput = new OcrInput())
{
// Load the PDF with the path to the document containing QR codes
qrInput.AddPdf("path_to_qr_pdf.pdf");
// Extract QR code content
var qrResults = Ocr.Read(qrInput);
// Print all recognized QR code data
foreach (var qr in qrResults.Barcodes)
{
Console.WriteLine($"Type: {qr.Type}, Value: {qr.Value}");
}
}
}
}
// This code sample demonstrates the process of installing and using Iron OCR to read barcodes and QR codes from PDFs in C#.
// First, install Iron OCR via NuGet Package Manager:
// Use the Package Manager Console and run the following command:
// Install-Package IronOcr
// Import the IronOCR namespace
using IronOcr;
class Program
{
static void Main()
{
// Set the license key for Iron OCR
var Ocr = new IronTesseract();
// Initialize the OCR engine
// Setting the language to English
Ocr.Language = OcrLanguage.English;
// Load a PDF document and automatically recognize all barcodes and QR codes
using (var input = new OcrInput())
{
// Load the PDF with the path to the document containing barcodes
input.AddPdf("path_to_barcode_pdf.pdf");
// Extract barcode content
var results = Ocr.Read(input);
// Print all recognized barcode and QR code data
foreach (var barcode in results.Barcodes)
{
Console.WriteLine($"Type: {barcode.Type}, Value: {barcode.Value}");
}
}
// Similarly, to extract QR codes from another PDF document, perform the following:
using (var qrInput = new OcrInput())
{
// Load the PDF with the path to the document containing QR codes
qrInput.AddPdf("path_to_qr_pdf.pdf");
// Extract QR code content
var qrResults = Ocr.Read(qrInput);
// Print all recognized QR code data
foreach (var qr in qrResults.Barcodes)
{
Console.WriteLine($"Type: {qr.Type}, Value: {qr.Value}");
}
}
}
}
' This code sample demonstrates the process of installing and using Iron OCR to read barcodes and QR codes from PDFs in C#.
' First, install Iron OCR via NuGet Package Manager:
' Use the Package Manager Console and run the following command:
' Install-Package IronOcr
' Import the IronOCR namespace
Imports IronOcr
Friend Class Program
Shared Sub Main()
' Set the license key for Iron OCR
Dim Ocr = New IronTesseract()
' Initialize the OCR engine
' Setting the language to English
Ocr.Language = OcrLanguage.English
' Load a PDF document and automatically recognize all barcodes and QR codes
Using input = New OcrInput()
' Load the PDF with the path to the document containing barcodes
input.AddPdf("path_to_barcode_pdf.pdf")
' Extract barcode content
Dim results = Ocr.Read(input)
' Print all recognized barcode and QR code data
For Each barcode In results.Barcodes
Console.WriteLine($"Type: {barcode.Type}, Value: {barcode.Value}")
Next barcode
End Using
' Similarly, to extract QR codes from another PDF document, perform the following:
Using qrInput = New OcrInput()
' Load the PDF with the path to the document containing QR codes
qrInput.AddPdf("path_to_qr_pdf.pdf")
' Extract QR code content
Dim qrResults = Ocr.Read(qrInput)
' Print all recognized QR code data
For Each qr In qrResults.Barcodes
Console.WriteLine($"Type: {qr.Type}, Value: {qr.Value}")
Next qr
End Using
End Sub
End Class
Further Reading: How to Read Barcodes and QR Codes