Skip to content

Instantly share code, notes, and snippets.

@groupdocs-com-kb
Last active October 19, 2024 11:06
Scan QR Code from PDF using C#. For more information, please follow link: https://kb.groupdocs.com/parser/net/scan-qrcode-from-pdf-using-csharp/
using GroupDocs.Parser;
using GroupDocs.Parser.Data;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ScanQRCodefromPDFusingCSharp
{
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.pdf"))
{
// 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);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment