彩票走势图

如何使用Aspose.BarCode和 Aspose.Pdf从Pdf文档中识别条码

原创|其它|编辑:郝浩|2012-10-23 09:49:21.000|阅读 599 次

概述:在本文中,我们将讲解如何使用Aspose.BarCode for .NET 和 Aspose.Pdf for .NET从Pdf文档中识别条码。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

在本文中,我们将讲解如何使用Aspose.BarCode for .NET Aspose.Pdf for .NET从Pdf文档中识别条码。

步骤如下:

 1 使用 Aspose.Pdf for .NET从Pdf文档中提取图像

2 以流的形式保存提取的图像

3 将图像以流的形式传递到Aspose.BarCode for .NET

4 从图像中读取条码

C#

try
{
    // set the license for Aspose.BarCode for .NET and Aspose.Pdf for .NET components
    Aspose.BarCodeRecognition.License licenceBarCodeRecognition = new Aspose.BarCodeRecognition.License();
    licenceBarCodeRecognition.SetLicense(@"Aspose.Total.Product.Family.lic");

    Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
    licensePdf.SetLicense(@"Aspose.Total.Product.Family.lic");

    // bind the pdf document
    Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
    pdfExtractor.BindPdf(@"document.pdf");
    // set page range for image extraction
    pdfExtractor.StartPage = 1;
    pdfExtractor.EndPage = 1;
    // extract the images
    Console.WriteLine("Extracting images.....");
    pdfExtractor.ExtractImage();
    // save images to stream in a loop
    while (pdfExtractor.HasNextImage())
    {
        Console.WriteLine("Getting next image....");
        // save image to stream
        MemoryStream imageStream = new MemoryStream();
        pdfExtractor.GetNextImage(imageStream);
        imageStream.Position = 0;

        Console.WriteLine("Recognizing barcode....");
        // recognize the barcode from the image stream above
        Aspose.BarCodeRecognition.BarCodeReader barcodeReader = new Aspose.BarCodeRecognition.BarCodeReader(imageStream, BarCodeReadType.Code39Standard);
        while (barcodeReader.Read())
        {
            Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());
        }
        // close the reader
        barcodeReader.Close();
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
 

[VB.NET]

Try
	' set the license for Aspose.BarCode for .NET and Aspose.Pdf for .NET components
	Dim licenceBarCodeRecognition As New Aspose.BarCodeRecognition.License()
	licenceBarCodeRecognition.SetLicense("Aspose.Total.Product.Family.lic")

	Dim licensePdf As New Aspose.Pdf.License()
	licensePdf.SetLicense("Aspose.Total.Product.Family.lic")

	' bind the pdf document
	Dim pdfExtractor As New Aspose.Pdf.Facades.PdfExtractor()
	pdfExtractor.BindPdf("docuemnt.pdf")
	' set page range for image extraction
	pdfExtractor.StartPage = 1
	pdfExtractor.EndPage = 1
	' extract the images
	Console.WriteLine("Extracting images.....")
	pdfExtractor.ExtractImage()
	' save images to stream in a loop
	Do While pdfExtractor.HasNextImage()
		Console.WriteLine("Getting next image....")
		' save image to stream
		Dim imageStream As New MemoryStream()
		pdfExtractor.GetNextImage(imageStream)
		imageStream.Position = 0

		Console.WriteLine("Recognizing barcode....")
		' recognize the barcode from the image stream above
		Dim barcodeReader As New Aspose.BarCodeRecognition.BarCodeReader(imageStream, BarCodeReadType.Code39Standard)
		Do While barcodeReader.Read()
			Console.WriteLine("Codetext found: " & barcodeReader.GetCodeText() & ", Symbology: " & barcodeReader.GetReadType().ToString())
		Loop
		' close the reader
		barcodeReader.Close()
	Loop
Catch ex As Exception
	Console.WriteLine(ex.Message)
End Try


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP