Aspose.BarCode如何从Word文档中识别条形码

作者:控件中国网   出处:控件中国网   2016-08-11 14:49:20   阅读:11

Aspose.BarCode是一款条形码生成与识别控件,支持多种现在常用的一维条形码和二维条形码,该产品可以和Aspose.Words控件一起结合使用在Word文档中生成和识别条形码,这篇文章主要介绍怎么从Word文档中识别条形码,首先需要使用Aspose.Words从Word文档中提取条形码图片,然后保存图片为流的形式,最后使用Aspose.BarCode来识别这些条形码,具体可以参考下面的代码:
// Load the word document
Document wordDocument = new Document("Invitation.doc");
// get all the shapes
NodeCollection shapes = wordDocument.GetChildNodes(NodeType.Shape, true, false);
// loop through all the shapes
foreach (Shape shape in shapes)
{
    // check if it has an image
    if (shape.HasImage)
    {
        // save the image in memory stream
        MemoryStream imgStream = new MemoryStream();
        shape.ImageData.Save(imgStream);
 
        // recognize the barcode from the image stream above
        BarCodeReader reader = new BarCodeReader(new Bitmap(imgStream), BarCodeReadType.Code39Standard);
        while(reader.Read())
        {
            Console.WriteLine("Codetext found: " + reader.GetCodeText());
        }
        // close the reader
        reader.Close();
    }
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat