Some test text!
Core / Guides / Workflow
Copy BarcodeModuleWindows.zip into your PDFNetC directory, then extract it locally. You should have files like
Copy BarcodeModuleLinux.tar.gz into your PDFNetC directory, then extract it. You should have files like
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.
The Barcode Module can detect and extract the barcodes present in a document, returning the result as JSON.
Specify the name of the input PDF file and the name of the output JSON file:
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json");
Specify the name of the input PDF file:
string json = BarcodeModule.ExtractBarcodesAsString("barcodes.pdf", "barcodes.json");
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.
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:
BarcodeOptions options = new BarcodeOptions();
options.SetBarcodeProfile(BarcodeOptions.BarcodeProfile.e_small_barcodes_profile);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);
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);
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:
For example, if you are only interested in barcodes that are oriented horizontally or vertically, you could specify e_horizontal | e_vertical
.
BarcodeOptions options = new BarcodeOptions();
options.SetBarcodeOrientations(BarcodeOptions.BarcodeOrientation.e_horizontal | BarcodeOptions.BarcodeOrientation.e_vertical);
BarcodeModule.ExtractBarcodes("barcodes.pdf", "barcodes.json", options);
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);
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