How to Read Barcodes from PDF in C#
IronBarcode enables direct barcode reading from PDF documents without converting to images first, using the ReadPdf method to extract barcode data from invoices, shipping labels, and reports in just one line of code.
Reading barcodes from PDF documents means detecting and decoding barcodes within PDF pages. This technology extracts encoded information directly from digital documents, eliminating manual scanning of printed barcodes. It automates workflows for processing invoices, shipping labels, reports, and other documents containing barcode data.
Quickstart: Reading Barcodes Directly from a PDF
Use IronBarcode's ReadPdf method to read barcodes from PDFs without converting to images. Extract barcode data with one line of code, then add advanced options as needed.
Get started making PDFs with NuGet now:
Install IronBarcode with NuGet Package Manager
Copy and run this code snippet.
var results = IronBarCode.BarcodeReader.ReadPdf("invoice.pdf");Deploy to test on your live environment
What Are the Basic Steps to Read PDF Barcodes?
- Install the barcode library to process barcode files. Check our NuGet Packages guide for platform-specific installation.
- Create
PdfBarcodeReaderOptionsif required. - Use the
ReadPdfmethod fromBarcodeReaderto read barcodes from PDFs. - Specify additional barcode reading options using
BarcodeReaderOption. - Extract barcode values.
How Do I Read Barcodes from PDF Documents Directly?
IronBarcode reads barcodes directly from PDF documents without requiring conversion to images. For a comprehensive overview of all features, visit our Features page. Use the BarcodeReader.ReadPdf() method, which accepts these PDF input types:
byte[]array: PDF document as a byte array.IEnumerable<Byte[]>: PDF documents as byte arrays stored in a collection.MemoryStream: PDF documents as MemoryStream type.IEnumerable<Stream>: PDF documents as a collection of MemoryStream. See our Read Barcode from Streams guide.String: PDF document path as a string or filename if copied into the project.IEnumerable<String>: PDF document path/name strings stored in a collection.
The BarcodeReader.ReadPdf() method also accepts PdfBarcodeReaderOptions for advanced reading capabilities, discussed in the next section. Here's how to use BarcodeReader.ReadPdf() to read barcodes in PDF documents:
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-pdf-1.csusing IronBarCode;
using System;
using System.Collections.Generic;
List<String> docs = new List<String>();
docs.Add(@"pdf_a.pdf");
docs.Add(@"pdf_b.pdf");
var myBarcode = BarcodeReader.ReadPdfs(docs); //can also accept individual PDF document file path as argument
foreach (var value in myBarcode)
{
Console.WriteLine(value.ToString());
}Imports IronBarCode
Imports System
Imports System.Collections.Generic
Private docs As New List(Of String)()
docs.Add("pdf_a.pdf")
docs.Add("pdf_b.pdf")
Dim myBarcode = BarcodeReader.ReadPdfs(docs) 'can also accept individual PDF document file path as argument
For Each value In myBarcode
Console.WriteLine(value.ToString())
Next valuePass the PDF file path string to BarcodeReader.ReadPdf() to read barcode values. For more examples on reading barcodes from different sources, check our Reading Barcodes in C# / .NET tutorial. To print all barcode values found in the PDF, iterate through the results using a foreach loop and call ToString() on each element. This example also demonstrates using a collection of PDF document names as the method argument.
How Can I Read Multiple PDFs at Once?
IronBarcode provides a ReadPdfs method to process multiple PDFs simultaneously. This method extracts barcodes from a list of PDFs efficiently. For handling multiple barcodes within documents, see our guide on Read Multiple Barcodes.
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-pdf-read-from-multiple-pdf.csusing IronBarCode;
using System;
using System.Collections.Generic;
using System.IO;
// Get all PDF files from a directory and add to list
string folderPath = @"PATH_TO_YOUR_FOLDER";
List<string> docs = new List<string>(Directory.GetFiles(folderPath, "*.pdf"));
// Read barcodes from all PDFs
var docResult = BarcodeReader.ReadPdfs(docs);
// Print results
foreach (var doc in docResult)
{
foreach (var item in doc)
{
Console.WriteLine("Barcode " + item.ToString() + " found at page " + item.PageNumber);
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comThis code retrieves all PDF files from a directory, adds them to a List<string>, and calls ReadPdfs with the list as input. The method returns an array of BarcodeResults. Loop through the results to access barcodes from each PDF.
How Do I Configure PDF Barcode Reader Options?
Configure barcode reading from PDFs using PdfBarcodeReaderOptions. For a detailed explanation of all reader settings, visit our Set PDF Barcode Reader Options example. Adjusting these properties improves quality, accuracy, and performance. PdfBarcodeReaderOptions inherits all BarcodeReaderOptions properties and adds PDF-specific options. Specify page numbers when instantiating PdfBarcodeReaderOptions:
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-pdf-2.csusing IronBarCode;
using System.Collections.Generic;
List<int> pageNumber = new List<int>() { 1, 2, 3 };
PdfBarcodeReaderOptions PdfOptions = new PdfBarcodeReaderOptions(pageNumber) // can also use individual page number as argument
{
// Properties of PDF Barcode reader options
};Imports IronBarCode
Imports System.Collections.Generic
Private pageNumber As New List(Of Integer)() From {1, 2, 3}
Private PdfOptions As New PdfBarcodeReaderOptions(pageNumber)Explore the additional properties available in PdfBarcodeReaderOptions beyond those inherited from BarcodeReaderOptions.
How Does DPI Setting Affect Barcode Reading?
Set the DPI (Dots Per Inch) of barcode images in PDF documents. This improves reading of low-quality barcodes. Use an Integer value. Default DPI is 150. For smaller or lower-quality barcodes, increase to 300 or 600 for better recognition. Higher DPI values increase processing time and memory usage.
When Should I Specify Page Numbers?
Specify page numbers containing barcodes to improve performance, especially for multi-page PDFs. IronBarcode skips pages without barcodes when you provide specific page numbers. Page numbering is 1-based (first page is 1, not 0). For optimization techniques with large documents, see our guide on Reading Speed Options.
How Do I Handle Password-Protected PDFs?
Work with encrypted PDF files by providing the password as a String input. IronBarcode cannot retrieve PDF passwords. Ensure you have necessary permissions and store passwords securely in your application.
What Scale Factor Should I Use for Small Barcodes?
Control the scale factor for width and height when converting to images. Accepts an Integer value with a default of 3.5. Higher scale factors help read small barcodes by zooming the PDF. For barcodes under 1 inch, use scale factor 5.0 or higher. High scale factors impact performance.
How Do I Implement Advanced Barcode Reading from PDFs?
Apply PdfBarcodeReaderOptions properties in your project to enhance barcode reading from PDF documents. For additional troubleshooting tips when barcodes aren't recognized, refer to our Barcode Not Recognized guide.
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-pdf-3.csusing IronBarCode;
using System;
using System.Collections.Generic;
List<int> pageNumber = new List<int>() { 1, 2, 3 };
PdfBarcodeReaderOptions PdfOptions = new PdfBarcodeReaderOptions(pageNumber)
{
DPI = 150,
//PageNumbers = pageNumber, //this property is not needed if page numbers has been specified as the argument in PdfBarcodeReaderOptions
Password = "barcode",
Scale = 3.5,
//properties below are some of the properties inherited from BarcodeReaderOptions
Speed = ReadingSpeed.Detailed,
ExpectBarcodeTypes = BarcodeEncoding.Code93,
ExpectMultipleBarcodes = true
};
var myBarcode = BarcodeReader.ReadPdf(@"pdf_a_filepath.pdf", PdfOptions);
foreach (var value in myBarcode)
{
Console.WriteLine(value.ToString());
}Imports IronBarCode
Imports System
Imports System.Collections.Generic
Private pageNumber As New List(Of Integer)() From {1, 2, 3}
Private PdfOptions As New PdfBarcodeReaderOptions(pageNumber) With {
.DPI = 150,
.Password = "barcode",
.Scale = 3.5,
.Speed = ReadingSpeed.Detailed,
.ExpectBarcodeTypes = BarcodeEncoding.Code93,
.ExpectMultipleBarcodes = True
}
Private myBarcode = BarcodeReader.ReadPdf("pdf_a_filepath.pdf", PdfOptions)
For Each value In myBarcode
Console.WriteLine(value.ToString())
Next valueInitialize PdfBarcodeReaderOptions with a variable name to access and adjust properties. Pass page numbers as an argument during initialization to apply settings to specific pages. Alternatively, set page numbers using the PageNumbers property.
Use inherited BarcodeReaderOptions properties like ExpectMultipleBarcodes and ExpectBarcodeTypes to improve performance and accuracy. Apply configured PdfBarcodeReaderOptions by passing it as the second argument to BarcodeReader.ReadPdf(), with the PDF file path as the first argument.
For processing PDFs with imperfect or damaged barcodes, explore our Image Correction features that can be applied during PDF processing.
Frequently Asked Questions
How can I read barcodes from PDF files in C#?
IronBarcode provides a simple ReadPdf method that allows you to read barcodes directly from PDF documents without converting them to images first. You can extract barcode data from PDFs in just one line of code: var results = IronBarCode.BarcodeReader.ReadPdf("invoice.pdf");
What types of PDF inputs does the barcode reader accept?
IronBarcode's BarcodeReader.ReadPdf() method accepts multiple PDF input types including: byte arrays, collections of byte arrays, MemoryStream objects, collections of MemoryStreams, file path strings, and collections of file path strings. This flexibility allows you to work with PDFs from various sources.
Do I need to convert PDFs to images before reading barcodes?
No, IronBarcode reads barcodes directly from PDF documents without requiring any conversion to images. The library processes PDF files natively, which saves time and preserves the original quality of the barcode data.
What are the basic steps to implement PDF barcode reading?
To read barcodes from PDFs using IronBarcode: 1) Install the barcode library via NuGet, 2) Create PdfBarcodeReaderOptions if needed for advanced settings, 3) Use the ReadPdf method from BarcodeReader, 4) Optionally specify additional reading options using BarcodeReaderOption, and 5) Extract the barcode values from the results.
Can I configure advanced reading options for PDF barcode extraction?
Yes, IronBarcode supports advanced reading capabilities through PdfBarcodeReaderOptions. This allows you to customize the barcode reading process with specific parameters and options to optimize detection and accuracy for your particular use case.
What types of documents can benefit from PDF barcode reading?
IronBarcode's PDF barcode reading is ideal for automating workflows involving invoices, shipping labels, reports, and any other business documents containing barcode data. This eliminates the need for manual scanning of printed barcodes and streamlines document processing.






