Some test text!

Search
Hamburger Icon

Core / Guides / Workflow

Barcode Extraction on Server/Desktop

Installation Instructions

Windows

Copy BarcodeModuleWindows.zip into your PDFNetC directory, then extract it locally. You should have files like

  • Barcode_README.md
  • Lib\Windows\Barcode\BarcodeModule.dll
  • Lib\Windows\Barcode\*.dll

Linux

Copy BarcodeModuleLinux.tar.gz into your PDFNetC directory, then extract it. You should have files like

  • Barcode_README.md
  • Lib/Linux/BarcodeModule.so
  • Lib/Linux/lib*.so

Usage

The first thing to set up before the module can be used is the location of the Lib directory under which the external add-ons are installed, so that the SDK knows where to look for them. This is achieved via the PDFNet AddResourceSearchPath function. If a relative path is used, it is based on the end-user executable.

PDFNet.AddResourceSearchPath("../../../../../Lib/");

Note: do not specify the actual Windows/Barcode or Linux/Barcode directories, where the extension libraries are, but the parent "Lib" folder. This allows you to add a single resource search path for all installed modules.

For error handling purposes, it is generally advisable to test whether the module is available via the IsModuleAvailable function.

if (!BarcodeModule.IsModuleAvailable())
{
   // Barcode Module unavailable
}

If you have the module installed but the function still returns false, please double check that the correct path was used in AddResourceSearchPath earlier.

Barcode Extraction

The Barcode Module can detect and extract the barcodes present in a document, returning the result as JSON.

Extract barcodes to JSON file

Specify the name of the input PDF file and the name of the output JSON file:

BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json");

Extract barcode data as JSON string

Specify the name of the input PDF file:

string json = BarcodeModule.ExtractBarcodesAsString("barcodes.pdf", "barcodes.json");

Barcode Options

Although the default options will satisfy most common use cases, we offer a couple of options to customize the extraction behavior and unlock lesser-used functionality.

The options object is passed as the last parameter to any extraction function, as shown below.

Extraction Profile

As is the case with many detection problems, barcode extraction has an inherent tradeoff between accuracy and speed. We have exposed several "Barcode Profiles" which allow you to tailor this tradeoff to suit your specific needs. Currently, there are 4 profiles available:

  • High Quality Source Profile (default): This profile assumes a moderately high input quality, such as vector graphics, or an average to high quality scan of a flat paper. This setting provides the fastest barcode read performance.
  • Low Quality Source Profile: This profile is useful for scanned paper of very poor quality, such as a low resolution or noisy scan. The barcode read performance is slightly slower.
  • Small Barcodes Profile: This profile is suitable for vector graphics or scanned paper containing unusually small barcode(s). The barcode read performance is significantly slower.
  • Natural Picture Profile: This profile should be selected for natural pictures, such as photographs of real-world objects that contain a barcode. Specifically, barcodes that are skewed relative to the image plane will be detected much more consistently when this profile is selected. The barcode read performance is significantly slower.
BarcodeOptions options = new BarcodeOptions();
options.SetBarcodeProfile(BarcodeOptions.BarcodeProfile.e_small_barcodes_profile);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);

Select a Subset of Barcode Types

By default, all supported barcode types are searched for. If you are only interested in a subset of the supported barcode types, you can improve processing time by only searching for the types of interest. This is set using the BarcodeTypeGroup, which is a bitfield that can be bitwise OR'ed to combine multiple types. For example, if you were interested in QR and Micro QR codes, then you could specify e_qr | e_micro_qr.

BarcodeOptions options = new BarcodeOptions();
options.SetBarcodeSearchTypes(BarcodeOptions.BarcodeSearchTypes.e_qr | BarcodeOptions.BarcodeSearchTypes.e_micro_qr);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);

Search for Barcodes in a Particular Orientation

By default, all barcode orientations are searched for. If you have some prior knowledge of the orientation of the barcodes in your document, you can improve processing time by limiting the search to particular orientations. This is set using the BarcodeOrientation, which is a bitfield that can be bitwise OR'ed to combine multiple orientations. Supported orientations include:

  • Horizontal
  • Vertical
  • Diagonal

For example, if you are only interested in barcodes that are oriented horizontally or vertically, you could specify e_horizontal | e_vertical.

NOTE
This option only has an effect on the following barcode type groups (see Barcode Types ):
  • Linear
  • Post Net Planet
  • Four State
  • GS1 Databar Stacked
  • PDF417
  • Micro PDF417
  • Patch Code
  • Pharma Code
BarcodeOptions options = new BarcodeOptions();
options.SetBarcodeOrientations(BarcodeOptions.BarcodeOrientation.e_horizontal | BarcodeOptions.BarcodeOrientation.e_vertical);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);

Specify the Data Output Format

By default, barcodes will be decoded if possible. If the decoding is successful, the data will be stored in the "text" field of the output JSON. If the barcode data cannot be decoded, the data will be stored as a Base64-encoded string in the "data" field of the output JSON. If you would prefer to receive the data back in a consistent manner, or would prefer to decode the data yourself, you can force the module to return the encoded binary data (again, in the "data" field of the output JSON) by specifying e_binary as the output format

BarcodeOptions options = new BarcodeOptions();
options.SetDataOutputFormat(BarcodeOptions.OutputFormat.e_binary);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);

Select a Page Range

Use the Pages option to restrict the extraction to a selected range of pages.

This can be a single page number (such as "1" for the first page), or a range separated by a dash (such as "1-5", or "7-" for 7 and beyond). An empty string (default) means all pages are extracted. Multiple ranges can be combined with commas, for example, "1-3,5,10-".

BarcodeOptions options = new BarcodeOptions();
options.SetPages("1"); // extract page 1
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales