How To Read Barcode From PDF And Image Using Syncfusion OPX
ZXing (zebra crossing) is an open-source tool to decode barcodes within images that fall under the Apache 2.0 license. It allows users to scan most of the 1D and 2D barcodes, including QR codes and data matrix barcodes.
Syncfusion Barcode Reader OPX is used to optimize the working of ZXing with Syncfusion .NET PDF library. This scans the barcode from the PDF document and returns the barcode value and type.
Assembly Requirement
To use the Barcode Reader feature in applications, references need to be added to the following set of assemblies:
Assembly Name | Description |
Syncfusion.Pdf.Base | This assembly contains the core feature for manipulating and saving PDF documents. |
Syncfusion.Compression.Base | This assembly compresses the internal contents of a PDF document. |
Syncfusion.BarcodeReader.OPX | This assembly is the wrapper for the ZXing assembly using ZXing features. |
zxing | Decodes Barcode within the image |
using Syncfusion.BarcodeReader.OPX;
using Syncfusion.Pdf.Parsing;
Scanning Embedded PDF barcode images:
If the PDF contains barcodes as shapes, then it internally converts the PDF page into an image and then detects the barcode. The following is the code snippet for this:
BarcodeReader reader = new BarcodeReader("Barcode.pdf";, FormatType.PDF);
BarcodeResult result = reader.ScanBarcode();
Scanning PDF barcodes:
If the PDF contains a barcode as an image, then the image alone can be extracted and the barcode will then be detected. The following is the code snippet for this:
//Loads the existing document.
PdfLoadedDocument document = new PdfLoadedDocument(txtImageFile.Text);
//Exports the document as images.
images = document.ExportAsImage(0, document.Pages.Count);
foreach (Bitmap img in images)
{
BarcodeReader reader = new BarcodeReader(img);
BarcodeResult result = reader.ScanBarcode();
}
Supported Barcode types are: Aztec, Codabar, Code 39, Code 93, Code 128, Data Martix, EAN-8, EAN-13, IMB, ITF, MaxiCode, PDF417, QR Code, UPC-A, UPC-E, MSI.