Use aspose. barcode and aspose. Words to recognize the bar code from the Word documents.

Source: Internet
Author: User

Source: huide Control Network

In this article, we will use the aspose. barcode and aspose. Words controls to recognize bar codes from Word documents. The procedure is as follows:

1. Use aspose. Words for. Net to extract images from documents

2. Save the extracted image as a stream

3. Pass the image to aspose. barcode for. NET as a stream

4. Read the barcode from the image

[C #]

1234567891011121314151617181920212223 // 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]

123456789101112131415161718192021 ' 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(NewBitmap(imgStream), BarCodeReadType.Code39Standard)
      Do While reader.Read()          Console.WriteLine("Codetext found: "& reader.GetCodeText())
      Loop      ' close the reader       reader.Close()    End IfNext shape

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.