DEV Community

IronSoftware
IronSoftware

Posted on

Read Barcodes From PDFs in C#: Dynamsoft and IronBarcode

A freight invoice runs to several pages, and each page carries a tracking barcode that has to reach the right shipment record before the warehouse shift starts. With a few thousand invoices to process each night, a service that has to decode barcodes in C# from every page is first given more threads as the batch grows, and whether those threads help depends on how the reader schedules PDF pages.

Dynamsoft Barcode Reader .NET Edition installs from NuGet as Dynamsoft.DotNet.BarcodeReader.Bundle, and its user guide runs each capture through one class, CaptureVisionRouter. Its PDF scheduling is examined first, and IronBarcode then reads the same batch.

How does Dynamsoft read a multi-page invoice?

Dynamsoft returns one result per page from a single call. CaptureMultiPages takes the path to a file such as invoice-0412.pdf and a preset template, and multi-page PDF and TIFF reading has been in the SDK since 11.0.3000.

// Read the barcodes on every page of the PDF with the preset template
CapturedResult[] results = cvRouter.CaptureMultiPages(invoicePdf, PresetTemplate.PT_READ_BARCODES);
Enter fullscreen mode Exit fullscreen mode

Reading from PDF files needs no additional license, since 11.0.4000 removed the license check on the PDF module. Release 11.6.1000, from July 2026, made PDFRM_MULTIMODAL the default PDF reading mode, which extracts the vector graphics, text and embedded images of a page instead of rasterizing all of it.

Why do extra threads not speed up the PDF step?

Because PDF decoding does not support multithreading. Dynamsoft's FAQ states that even when the application uses several threads, PDF files are still processed single-threaded, because of the way PDF pages are handled internally. A parallel loop around CaptureMultiPages therefore does not spread the PDF work across threads, and the FAQ's advice for throughput is to convert the pages to images and decode those in parallel.

The router adds a second rule. Instances of CaptureVisionRouter are not thread-safe, so each worker thread needs its own router. Release 11.6.1000 also changed how decoding work is split across threads, and its notes do not say that PDF files use more than one thread after the change, so the FAQ remains the written answer.

The cost of rendering pages to images

The image route adds a rendering step before decoding. Each invoice page becomes an image file first, and each worker then runs the ordinary image capture with its own router.

// Create a separate router for this worker thread
using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
{
    // Capture one page image, rendered from its invoice beforehand
    CapturedResult? result = cvRouter.Capture("invoice-0412-page-03.png", PresetTemplate.PT_READ_BARCODES);

    // Print the tracking code of each decoded barcode
    DecodedBarcodesResult? barcodes = result?.GetDecodedBarcodesResult();
    foreach (BarcodeResultItem item in barcodes?.GetItems() ?? Array.Empty<BarcodeResultItem>())
    {
        Console.WriteLine("Tracking code: " + item.GetText());
    }
}
Enter fullscreen mode Exit fullscreen mode

The team then maintains a renderer, a folder of temporary page images and a mapping from each image back to its invoice and page number, so each tracking code is assigned to the correct record. The one-line PDF call was supposed to make that work unnecessary.

Reading the batch with IronBarcode's PDF options

IronBarcode reads the invoice PDF itself and takes its threading settings from the options object. BarcodeReader.ReadPdf accepts the file path, and PdfBarcodeReaderOptions carries the page selection and resolution along with the threading settings, so no rendering step precedes the read.

using IronBarCode;
using System;

// Let the reader take the PDF itself and spread its work across up to four threads
var options = new PdfBarcodeReaderOptions
{
    Multithreaded = true,
    MaxParallelThreads = 4
};

// Read the invoice PDF directly, with no rendering step
var results = BarcodeReader.ReadPdf("invoice-0412.pdf", options);

// Print each result with its page, so the tracking code maps back to the invoice
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}");
}
Enter fullscreen mode Exit fullscreen mode

The PDF options are documented in IronBarcode's guide to reading barcodes from PDFs, and the threading settings in its example of setting the maximum parallel threads. The result's page number replaces the image-to-invoice mapping, and there is no temporary folder to clean up after the batch.

When a scanned invoice is skewed or noisy, the same options object takes image filters and automatic rotation, and IronBarcode's image correction guide lists the filters. For services that read on request instead of in a nightly job, IronBarcode documents asynchronous and multithreaded reading with BarcodeReader.ReadAsync.

Dynamsoft's strengths outside PDF scheduling

Dynamsoft Barcode Reader is capable away from the PDF question. The vendor describes the engine as engineered for blurred, damaged and low-light barcodes, and a preset template such as PT_READ_BARCODES keeps a first capture to a single call.

The release notes show steady maintenance. Version 11.6.6000 is dated 26 November 2026, 11.6.4000 fixed a crash in Capture() when input byte data cannot be parsed, and 11.6.3000 fixed a hang that could occur during multithreaded processing.

PDF batches ahead of image jobs

Of the barcode jobs in the warehouse, only the nightly invoice batch carries a rendering step and a page mapping, so it is the one to move before the others. Delivery notes and returns paperwork share its ReadPdf call and follow it, while the image jobs that already run in parallel and the photographed dock labels, with image filters and automatic rotation, can wait until the PDF jobs are settled.

IronBarcode read a three-page test invoice in our run of the listing on 27 November 2026, under BarCode 2026.11.3 and .NET 8, and printed Page 1: TRK-0412-01 through Page 3: TRK-0412-03, and BarCode 2026.12.4 printed the same on 3 December 2026. The tracking codes from one night of real invoices can then be compared page by page with the existing output. Reading your own invoices takes a trial key from the IronBarcode licensing page.

Dynamsoft and Dynamsoft Barcode Reader are trademarks of their respective owners, we have no affiliation with Dynamsoft, and the facts above are based on Dynamsoft's public documentation, FAQ and release notes, NuGet records and IronBarcode's documentation.

Top comments (0)