Scan QR Code from DOCX using C#

In today’s digital world, QR codes are increasingly utilized for various applications, including marketing, payments, and data sharing. If you’re working with DOCX files and need to scan QR Code from DOCX using C#, you can easily achieve it using GroupDocs.Parser library. In this article, we’ll guide you through this process along with sample code example. The library discussed in this article is a robust tool for parsing and extracting data from multiple document formats, including DOCX. It provides a wide range of features that simplify the extraction of barcodes, including QR codes, from documents without the need for any additional software. Before implementing this functionality, ensure you have Visual Studio installed on your machine and a .NET environment set up for C# development. Following key steps explain the process of how to extract QR Code from DOCX in C#.

Steps to Scan QR Code from DOCX using C#

  1. Set up your development environment and add the GroupDocs.Parser for .NET library into your project for QR code scanning from DOCX
  2. Create a Parser object by providing the path to your DOCX file as an argument to its constructor
  3. Use the Parser.GetBarcodes method to retrieve the PageBarcodeArea collection for barcodes of the type ‘QR’
  4. Lastly, loop through the filtered barcode collection to access and extract the QR code data contained within the DOCX file

The Parser library offers a highly versatile solution that facilitates QR Code extraction from DOCX C# on multiple operating systems, including Windows, macOS, and Linux. By utilizing the .NET, developers can maintain a consistent development environment, which simplifies implementation regardless of the chosen platform. Once you have installed the necessary library and configured the appropriate file paths, integrating the code into your projects becomes straightforward and efficient. The following code example demonstrates how to read QR Codes from DOCX files effectively.

Code to Scan QR Code from DOCX using C#

using GroupDocs.Parser;
using GroupDocs.Parser.Data;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ScanQRCodefromDOCXusingCSharp
{
internal class Program
{
static void Main(string[] args)
{
// Apply the license to remove the restrictions imposed
// by the Parser library
License lic = new License();
lic.SetLicense(@"GroupDocs.Parser.lic");
// Instantiate an object of the Parser class to enable access to its
// methods and properties for processing or manipulating data
using (Parser parser = new Parser("input.docx"))
{
// Verify if the file is compatible for QR extraction
if (!parser.Features.Barcodes)
{
Console.WriteLine("The file doesn't support QR extraction.");
return;
}
// Scan and extract only the barcodes of type "QR" from your file
IEnumerable<PageBarcodeArea> qrcodes = parser.GetBarcodes()
.Where(i => i.CodeTypeName == "QR");
// Iterate over QR codes
foreach (PageBarcodeArea qrcode in qrcodes)
{
// Print the page index
Console.WriteLine("Page: " + (qrcode.Page.Index + 1));
// Print the barcode value
Console.WriteLine("Value: " + qrcode.Value);
}
}
}
}
}

With Parser library, C# read QR Code from DOCX documents is both efficient and easy to implement across various platforms. The library’s powerful features enable developers to focus on core application logic while ensuring seamless barcode extraction. By leveraging this process, you can significantly enhance your application’s ability to process DOCX files and extract valuable data encoded in QR codes. Whether you’re building solutions for data automation or document management, this library is reliable for QR code scanning on any platform.

Previously, we provided a guide on scanning QR Codes from PDF using C#. For a comprehensive explanation, don’t miss our full tutorial on how to scan QR Code from PDF using C#.

 English