Skip to end of metadata
Go to start of metadata

PDF documents usually comprise text, images, tables, attachments, graphs, annotations and other objects. Some of our customers need to embed barcodes in documents and then identify barcodes in the PDF file. The following article explains how to transform the pages in a PDF file to images and identifying barcodes in the images with Aspose.Barcode for .NET.

Converting Pages to Images and Recognizing Barcodes

Aspose.PDF for .NET is very powerful product for managing PDF documents. It makes it easy to convert pages in PDF documents to images. Aspose.BarCode for .NET is an equally powerful product for generating and recognizing barcodes.

The class PdfConverter under the Aspose.PDF.Facades namespace supports converting PDF pages to various image formats. The PngDevice under the Aspose.PDF.Devices namespace supports converting PDF pages to PNG files. Either of these classes can be used to transform pages of PDF file into images.

When the pages have been converted to an image format, we can use Aspose.BarCode for .NET to identify barcodes inside them. The code samples below show how to convert pages using either PdfConverter or PngDevice.

Using Aspose.PDF.Facades

The PdfConverter class contains a method named GetNextImage which generates the an image from the current PDF page. To specify the output image format, this method accepts an argument from the System.Drawing.Imaging.ImageFormat enumeration.

Aspose.Barcode contains a namespace, BarCodeRecognition, which contains the BarCodeReader class. The BarCodeReader class lets you read, determine, and identify barcodes from image files.

For the purposes of this example, first convert a page in a PDF file into an image with Aspose.PDF.Facades.PdfConverter. Then use the Aspose.BarCodeRecognition.BarCodeReader class to recognize the barcode in the image.

Programming Samples

In above code snippets the output image is saved to a MemoryStream object. The image can also be saved to disk. To do so, replace the MemorStream object with a string object that represents the file path to the PdfConverter class' GetNextImage method.


Using the PngDevice Class

In the Aspose.PDF.Devices, is the PngDevice. This class lets you convert pages in PDF documents to PNG images.

For the purpose of this example, load the source PDF file into the Document object and use the PngDevice class to transform the input document's pages into PNG images. When the images have been created, use the BarCodeReader class under the Aspose.BarCodeRecognition to identify and read barcodes in the images.

The code samples given here traverses through the pages of the PDF document and tries to identify barcodes on each page.

Programming Samples

For further information on topics covered in this article, please go to:

  • No labels