Created
November 6, 2024 20:35
-
-
Save conholdate-gists/365a844ab202436402281fe9de20cb11 to your computer and use it in GitHub Desktop.
Scan Barcode from Word Document in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open the Word document | |
Aspose.Words.Document wordDoc = new Aspose.Words.Document("BarcodeDocument.docx"); | |
// Process all word pages | |
for (int i = 0; i < wordDoc.PageCount; ++i) | |
{ | |
// Create options to save | |
Aspose.Words.Saving.ImageSaveOptions wordSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png); | |
// Set required page | |
wordSaveOptions.PageSet = new Aspose.Words.Saving.PageSet(i); | |
// Set rendering resolution to 300 dpi | |
wordSaveOptions.Resolution = 300;//300 dpi | |
// Render pages to a memory stream | |
MemoryStream ms = new MemoryStream(); | |
wordDoc.Save(ms, wordSaveOptions); | |
ms.Position = 0; | |
// Recognize PDF417, QR Code, Data Matrix, and Aztec barcode types from the rendered image of the page | |
Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(ms, Aspose.BarCode.BarCodeRecognition.DecodeType.Pdf417, Aspose.BarCode.BarCodeRecognition.DecodeType.QR, Aspose.BarCode.BarCodeRecognition.DecodeType.DataMatrix, Aspose.BarCode.BarCodeRecognition.DecodeType.Aztec); | |
foreach (Aspose.BarCode.BarCodeRecognition.BarCodeResult result in reader.ReadBarCodes()) | |
Console.WriteLine($"Barcode type:{result.CodeTypeName}, Barcode Data:{result.CodeText}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment