使用Aspose.BarCode 和 Aspose.Words从Word文档中识别条码

来源:慧都控件网

在本文中,我们将使用Aspose.BarCodeAspose.Words这两个控件实现从Word文档中识别条码。步骤如下:

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

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

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

4 、从图像中读取条码

[C#]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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();
     }

[VB.NET]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
' Load the word document
Dim wordDocument As Document = New Document( "Invitation.doc" )
' get all the shapes
Dim shapes As NodeCollection = wordDocument.GetChildNodes(NodeType.Shape, True , False )
' loop through all the shapes
For Each shape As Shape In shapes
    ' check if it has an image
    If shape.HasImage Then
       ' save the image in memory stream
       Dim imgStream As MemoryStream = New MemoryStream()
       shape.ImageData.Save(imgStream)
  
       ' recognize the barcode from the image stream above
       Dim reader As BarCodeReader = New BarCodeReader( New Bitmap(imgStream), BarCodeReadType.Code39Standard)
       Do While reader.Read()
          Console.WriteLine( "Codetext found: " & reader.GetCodeText())
       Loop
       ' close the reader
       reader.Close()
    End If
Next shape
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值