Scan Barcode from Word DOCX in C#

Scanning barcodes embedded in Word documents can be crucial for many business and document processing workflows, allowing quick data extraction from physical documents or digital files. In this tutorial, we’ll walk through the process of scanning barcodes from a Word DOCX or DOC document using C#.

With this method, you’ll be able to detect various barcode types like PDF417, QR codes, Data Matrix, and Aztec codes directly from DOCX files.

It contains the following sub-headings to cover all the details:

Why Scan Barcodes from Word Documents?

There are several practical scenarios where extracting barcodes from Word documents is beneficial:

  • Inventory and Asset Management: Barcodes embedded in documents simplify asset tracking and stock management.

  • Document Verification: Scanning barcodes directly from Word files helps verify document authenticity.

  • Automated Data Entry: Automatically pulling barcode information reduces manual data entry errors.

  • Workflow Automation: Automate document processing workflows by extracting and processing barcode data directly.

Barcode Scanning in DOCX - C# API Configuration

You can read barcodes in the Word documents in DOC or DOCX format by installing Conholdate.Total for .NET using the NuGet plugin manager by pasting the installation command below:

PM> NuGet\Install-Package Conholdate.Total

Scan Barcodes from Word DOCX Documents in C#

  • Open the Word Document: We load the Word document into an Aspose.Words.Document object.

  • Process Each Page: Using a loop, we go through each page of the Word document to ensure that all barcodes are scanned.

  • Save Page as Image: Each page is saved as a PNG image in a memory stream at 300 DPI. This high resolution ensures accurate barcode recognition.

  • Initialize Barcode Reader: We initialize the Aspose.BarCode.BarCodeRecognition.BarCodeReader with the image in the memory stream. Here, we specify the barcode types we want to recognize (PDF417, QR, Data Matrix, and Aztec).

  • Read Barcodes and Display Data: For each barcode found, the code prints the barcode type and data to the console.

Here’s the code snippet that demonstrates how to scan barcodes from each page of a Word document using C#:

Get a Free License

You may get a free temporary license to check different features offered by the API to their full capacity.

Summing up

By following this guide, you can efficiently scan and extract barcodes from Word documents using C#. This method is perfect for applications needing fast, accurate barcode data extraction from digital or scanned Word files. In case of any questions, please write to us at the forum.

See Also