Free Support Forum - aspose.com

Qr code from pdf is not recognized

for a new project i want to test aspose.barcode. but unfortunately only 50% of the QR code is recognized. am i doing something wrong? Or why are the QR codes not recognized?

using Aspose.BarCode;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.BarCode.ComplexBarcode;
using Aspose.Pdf;

using Aspose.Pdf.Devices;
using System;
using System.Drawing.Imaging;
using System.IO;

namespace ConsoleApp11
{
class Program
{
// PDF Path import
public const string dataDirPDF = “C:\Daten\Aspose\”;

    static void Main(string[] args)
    {            
        // List all PDF's in Folder
        DirectoryInfo d = new DirectoryInfo(@dataDirPDF);
        FileInfo[] Files = d.GetFiles("*.pdf"); 
        
        foreach (FileInfo file in Files)
        {   
            // Create PNG from PDF
            ReadQRCode(file.FullName);
        }
               
        Console.WriteLine("Abgeschlossen");
        Console.ReadLine();
    }
  
    static void ReadQRCode(string filename)
    {
        Aspose.BarCode.License license = new Aspose.BarCode.License();
        license.SetLicense("Aspose.BarCode.lic");

        Console.WriteLine(filename);

        try
        {
            // Bind the pdf document
            Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
            pdfExtractor.BindPdf(filename);
            
            // Extract the images
            pdfExtractor.ExtractImage();

            // Save images to stream in a loop
            while (pdfExtractor.HasNextImage())
            {
                // Save image to stream
                MemoryStream imageStream = new MemoryStream();
                pdfExtractor.GetNextImage(imageStream);
                imageStream.Position = 0;
                int found = 0;

                // Recognize the barcode from the image stream above
                using (BarCodeReader reader = new BarCodeReader(imageStream, DecodeType.QR))
                {
                    foreach (BarCodeResult barcodeResult in reader.ReadBarCodes())
                    {
                        found = 1;
                        var result = barcodeResult.CodeText.Split(new string[] { "\n" }, StringSplitOptions.None);

                        Console.WriteLine("************");
                        Console.WriteLine("Zeile 3 " + result[3]);
                        Console.WriteLine("Zeile 28 " + result[28]);
                        Console.WriteLine("************");
                        Console.WriteLine("\n");
                   
                    }
                }
                if (found == 0) {
                    Console.WriteLine("no QR Found");
                }

            }
           
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

    }

}

}
for example this qr code is not recognized
qr-factsheet.pdf (133.6 KB)

@Giani,

Please notice, I am able to reproduce the issue as you mentioned using your template file and sample code. I found QR code is not recognized by Aspose.BarCode for .NET recognition engine. I have logged a ticket with an id " BARCODENET-37754" for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Thanks for the quick reply

@Giani,

You are welcome.