原創(chuàng)|其它|編輯:郝浩|2012-10-23 10:34:23.000|閱讀 374 次
概述:在本文中,我們將使用Aspose.BarCode 和 Aspose.Words這兩個控件實現(xiàn)從Word文檔中識別條碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本文中,我們將使用Aspose.BarCode 和 Aspose.Words這兩個控件實現(xiàn)從Word文檔中識別條碼。步驟如下:
1、使用Aspose.Words for .NET從文檔中提取圖像
2 、以流的形式保存提取的圖像
3 、將圖像以流的形式傳遞到Aspose.BarCode for .NET中
4 、從圖像中讀取條碼
[C#]
// 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]
' 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
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網(wǎng)