How to Read Barcode from PDF Documents
Recognize Barcode from PDF Documents
In this article, we will recognize the barcode from a pdf document using Aspose.BarCode for .NET and Aspose.PDF for .NET. We will follow the below steps for reading the barcode from the PDF document:
- Extract image from a pdf document using Aspose.PDF for .NET using PdfExtractor or PdfConverter.
- Save the extracted image as a stream.
- Pass the image in the form of the stream to Aspose.BarCode for .NET.
- Read the barcode from the image.
Use the PdfExtractor class and bind it to the PDF document using PdfExtractor.BindPdf() method. Specify start and end page numbers and then call PdfExtractor.ExtractImage() method to get the images for the mentioned pages. In a while loop, call PdfExtractor.GetNextImage() method and save the image to stream. Initialize Aspose.BarCodeRecognition.BarCodeReader class with the stream and symbology type and then call BarCodeReader.Read() method to read the barcodes from the stream (image). The sample code snippet is given below:
PdfConverter class converts whole pages of the PDF document into images instead of extracting images from pages. Use PdfConverter for reading barcodes that occupie whole page, for Patch letters and if PdfExtractor fails to extract barcode images from your PDF document. Create instance of PdfConverter class. Bind it to the PDF document using PdfConverter.BindPdf() method. Specify start and end page numbers then set PdfConverter.RenderingOptions.BarcodeOptimization setting and then call PdfConverter.DoConvert() method to initialize converter. In a while loop, call PdfConverter.GetNextImage() method and save the page image to stream. Initialize Aspose.BarCodeRecognition.BarCodeReader class with the stream and symbology type and then call BarCodeReader.Read() method to read the barcodes from the stream (image). The sample code snippet is given below:
The evaluation version of Aspose.BarCode for .NET provides limited functionality. For getting a temporary license for 30 days, please visit http://www.aspose.com/corporate/purchase/temporary-license.aspx for more details.