Hi,
You can surely read BarCode from pdf files using Aspose.BarCode and Aspose.Pdf.Kit components. First, open the pdf file using PdfConverter class of Aspose.pdf.kit library, extract image(s) from it and use Aspose.BarCode to recognize the barcodes from the images.
Please refer to the sample code below: Call ExtractImage() method and modify the license and pdf paths. The trial version will only extract Code39 barcodes. If you want to recognize other barcode symbologies, please ask for a temporary license from http://www.aspose.com/purchase/templicense.aspx
using
Aspose.BarCode;
using
Aspose.Pdf.Kit;
public string ExtractImage()
{
string strBarCodes = "";
PdfConverter converter = new PdfConverter();
// bind converter object to pdf stream
converter.BindPdf(
@"c:\temp\sample.pdf");
converter.DoConvert();
//Calling HasNextImage method in while loop. When images will finish, loop will exit
while (converter.HasNextImage())
{
//Call GetNextImage method to store image as a file
MemoryStream imageStream = new MemoryStream();
converter.GetNextImage(imageStream);
// read the barcode from this image
String barcodeText = GetBarCodeText(imageStream);
if (barcodeText != null)
strBarCodes += barcodeText +
Environment.NewLine;
else
strBarCodes +=
"NO_BARCODE_FOUND" + Environment.NewLine;
}
return strBarCodes;
}
private String GetBarCodeText(MemoryStream imageStream)
{
// set the license file
Aspose.BarCode.
License lic = new Aspose.BarCode.License();
lic.SetLicense(
@"c:\Aspose.Total.lic");
// create bitmap from stream
Bitmap bitmap = new Bitmap(imageStream);
//Create a barcode reader
BarCodeReader reader = new BarCodeReader(bitmap);
// reader settings
reader.SymbologyType =
Symbology.DataMatrix;
// perform scan
Aspose.BarCode.
BarCodeInfo[] result;
result = reader.Read();
if (result.Length > 0)
{
return result[0].CodeText;
}
// barcode not found.
return null;
}
Best Regards,
Saqib Razzaq
Support Developer
Aspose Guangzhou Team