Free Support Forum - aspose.com

Exception while reading barcode


#1

We are reading Barcodes from pdf-Documents using the following c#-Code:
try
{
PdfExtractor extractor = GetPdfExtractor(byContent, nStartPage, nEndPage);

			while(extractor.HasNextImage())
			{
				MemoryStream imageStream = new MemoryStream();
				extractor.GetNextImage(imageStream);
				imageStream.Position = 0;
				Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream, DecodeType.AllSupportedTypes);
				reader.RecognitionMode = RecognitionMode.MaxQuality;

				while(reader.Read())
				{
					string strContent = reader.GetCodeText();
				}
			}
		}
		catch(Exception ex)
		{
			AdeNetFileBarcodeLog.Log.Error("Unable to read barcodes", ex);
		}

Unfortunately, an IndexOutOfRangeException occurs when reader.Read() is called. It’s not a general issue, but we have these problems with some of our documents. Attached is one of them.
We are currently using Aspose.Barcode 17.4.0.0 for .Net.
Segment 002 von eokarte-defekt.pdf (926.1 KB)


#2

@PhilippHaenggi,

Thanks for the template file and sample code segment.

Please try our latest version of Aspose.BarCode for .NET v19.1.

Moreover, I could not compile your code segment as some method(s) and other objects/variables definitions/values are missing. I tested your scenario/ case a bit using the following sample code and your template PDF file with Aspose.PDF for .NET v19.2 and Aspose.BarCode for .NET v19.1, it works and I could not find any exception:
e.g
Sample code:

 //open document
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("e:\\test2\\Segment 002 von eokarte-defekt.pdf");
            // traverse through individual pages of PDF file
            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                // traverse through each image extracted from PDF pages
                foreach (Aspose.Pdf.XImage xImage in pdfDocument.Pages[pageCount].Resources.Images)
                {
                    using (MemoryStream imageStream = new MemoryStream())
                    {
                        //save output image
                        xImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        // set the stream position to the begining of Stream
                        imageStream.Position = 0;

                        // Instantiate BarCodeReader object
                        Aspose.BarCode.BarCodeRecognition.BarCodeReader barcodeReader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream, Aspose.BarCode.BarCodeRecognition.DecodeType.AllSupportedTypes);
                        //barcodeReader.QualitySettings.RecognitionMode = Aspose.BarCode.BarCodeRecognition.RecognitionMode.MaxQuality;
                        barcodeReader.QualitySettings = Aspose.BarCode.BarCodeRecognition.QualitySettings.HighQuality;
                        while (barcodeReader.Read())
                        {
                            // get BarCode text from BarCode image
                            string code = barcodeReader.GetCodeText();
                            // write the BarCode text to Console output
                            Console.WriteLine("BARCODE : " + code);
                        }
                        // close BarCodeReader object to release the Image file
                        barcodeReader.Close();
                    }
                }
            }

If you still find the issue, kindly do create a simple console demo (runnable) application (you may zip the project prior attaching here) using latest versions of Aspose.BarCode (especially) to reproduce the issue on our end, we will check it soon.


#3

Thank you. It seems that the bug is fixed with the latest Version.


#4

@PhilippHaenggi,

Good to know that your issue is sorted out by the latest version/fix. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.