Using Thoughtworks and spirepdf trying to decode QR code
Check the code below
- private static void GetImages(string sourcePdf, string outputPath)
- {
- PdfDocument doc = new PdfDocument();
- doc.LoadFromFile(sourcePdf);
- outputPath = System.IO.Path.Combine(outputPath, String.Format(@"{0}.jpg", 0));
- for (int i = 0; i < doc.Pages.Count; i++)
- {
- string QRCodeString = "";
- PdfPageBase page = doc.Pages[i];
- System.IO.Stream[] images = page.ExtractImages();
- foreach (System.IO.Stream image in images)
- {
- QRCodeString = GetQRCodeString(Bitmap.FromStream(image), outputPath);
- if (QRCodeString == "")
- {
- continue;
-
- }
- else
- {
- QRCodeDecoder decoder = new QRCodeDecoder();
- String decodedString = decoder.decode(new QRCodeBitmapImage(new System.Drawing.Bitmap(image)), System.Text.Encoding.UTF8);
- Console.WriteLine(decodedString);
- }
- }
- Console.WriteLine(QRCodeString);
- }
- }
- private static string GetQRCodeString(System.Drawing.Image img, string outPutPath)
- {
- img.Save(outPutPath, System.Drawing.Imaging.ImageFormat.Jpeg);
- string scaningResult = Spire.Barcode.BarcodeScanner.ScanOne(outPutPath);
- System.IO.File.Delete(outPutPath);
- return scaningResult;
- }
It is working for those pdf having Bar code at the top right corner. And showing for other positions
Error: ThoughtWorks.QRCode.ExceptionHandler.DecodingFailedException: 'Give up decoding'
Please help