Click or drag to resize

Decode barcodes from PDF

This sample searches all pages of a PDF document for multiple barcodes. The PdfDecoder relies on the presence of the pdfium.dll file in the same directory as the executable. The sample executable should be built for either x86 or x64 platforms, depending on the version of pdfium.dll (32 or 64 bits) used.

C#
using Opait.Barcode;
using Opait.Barcode.Pdf;

// Decodes barcodes found in all pages of a PDF document.
static void DecodePdfBarcodes(string fileName)
{
    // Create a PDF decoder that also opens the specified PDF file.
    using (var pdfDecoder = new PdfDecoder(fileName))
    {
        // Create a barcode decoder class with default options.
        var decoder = new BarcodeDecoder();

        // PDF decoder can process a specified zone, a specific
        // page, or the entire document. Here we process the
        // file for multiple barcodes on each page.
        var results = pdfDecoder.DecodeMultiple(decoder);

        // Check for detection failure.
        if (results == null)
        {
            Console.WriteLine("Unable to find a barcode.");
            return;
        }

        // Display the results.
        foreach (var result in results)
        {
            Console.WriteLine($"Barcode Type: {result.BarcodeType}");
            Console.WriteLine($"Barcode Text: {result.Text}");
        }
    }
}