Sign In  Sign Up Live-Chat

How to recognize a barcode from a pdf file

Last post 05-09-2008, 10:43 AM by saqib.razzaq. 1 replies.
Sort Posts: Previous Next
  •  05-08-2008, 1:16 PM 126080

    How to recognize a barcode from a pdf file

    Hello,

     I'm testing the aspose.barcode recognition and I want to know if there is some way to recognize a barcode from a pdf file


    This message was posted using Aspose.Live 2 Forum
     
  •  05-09-2008, 10:43 AM 126261 in reply to 126080

    Re: How to recognize a barcode from a pdf file

    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

     
View as RSS news feed in XML