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.Barcoder.Api;

// Decodes barcodes found in all pages of the specified PDF file.
static void DecodePdfBarcodes(string fileName)
{
    // Initialize the barcoder library with default options.
    var barcoder = new Barcoder();

    // Create a PDF decoder that also opens the specified PDF file.
    using (var pdfDecoder = barcoder.CreatePdfDecoder(fileName))
    {
        // Create a barcode decoder class.
        var decoder = barcoder.CreateDecoder();

        // 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("No barcodes found");
            return;
        }

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