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)