Cannot read DecodeType.Code128 barcode

The barcode reader is unable to read the barcode of type DecodeType.Code128

Workflow Steps
1>We have created a barcode using DecodeType.Code128 and put on PDF page ( our clients use this page as separator sheet)
2>Our client then insert this barcode page between several physical documents and scanned them all, which creates big single PDF
3>Our splitting process then, loop through all pages and check if any page is barcode page, and splits the big PDF into individual small PDF

Issue is some times the scanned quality of the barcode is not that great, and in such case ASPOSE.Barcode unable to read the barcode,

I have attached couple of barcode PDF with low scanned quality, and aspose is not able to read these barcodes. I have tried different combinations of RecognitionMode and ManualHints options without any luck

Below is my code to identity barcode page

            using (var fs = new FileStream(file, FileMode.Open))
            {
                var pdfDocument = new Document(fs);
                foreach (Page page in pdfDocument.Pages)
                {
                    var isSeparator = splitter.IsSeparator(page);
                    Assert.IsTrue(isSeparator);
                }
            }

   public bool IsSeparator(Page page)
    {
        if (page.Resources.Images != null && page.Resources.Images.Count >= 1)
        {
            var img = page.Resources.Images[1];
            using (MemoryStream barcodeImage = new MemoryStream())
            {
                img.Save(barcodeImage, ImageFormat.Jpeg);
                barcodeImage.Seek(0L, SeekOrigin.Begin);

                using (BarCodeReader barcodeReader = new BarCodeReader(barcodeImage, _barcodeDecodeType))
                {
                    barcodeReader.RecognitionMode = RecognitionMode.MaxQuality;

                    while (barcodeReader.Read())
                    {
                        var barcodeText = barcodeReader.GetCodeText();
                        if (barcodeText.ToLower() == "eof")
                        {
                            return true;
                        }
                    }
                }
            }
        }

        return false;
    }

1.pdf (60.7 KB)
2.pdf (60.9 KB)

@Laksh,

Thank you for details. We have looked into the said issue. We are unable to reproduce the issue at our end. We have use the following sample code snippet to recognize the barcode from PDF document along with latest version of the API. It is always recommended to use the latest version of the API as it contains new features, improvements and bug fixes reported by other customer.

CODE:

            Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
            licensePdf.SetLicense(@"Aspose.Total.lic");

            // bind the pdf document
            Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
            pdfExtractor.BindPdf(@"173483_2.pdf");

            // extract the images
            pdfExtractor.ExtractImage();

            // save images to stream in a loop
            while (pdfExtractor.HasNextImage())
            {
                // save image to stream
                System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
                pdfExtractor.GetNextImage(imageStream);
                imageStream.Position = 0;

                Aspose.BarCode.BarCodeRecognition.BarCodeReader barcodeReader = 
                    new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream);

                while (barcodeReader.Read())
                {                        
                    Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType().ToString());
                }
                // close the reader
                barcodeReader.Close();
            }

OUTPUT:

Codetext found: eof, Symbology: Code128
Codetext found: eof, Symbology: Code128

Thanks ikram
The version i am using currently is 8.0.0.0 and the code above did not work this version. So i have downloaded latest version 18.2.0.0 for testing purpose however the evaluation version only support Code39Standard so i was not able to run your code with the latest version. ( and also in evaluation version assigning BaseDecodeType to Code39Standard did not work becuase the barcode was initially created using Code128 )

However, i was able to get it working using the PdfConverter instead of PdfExtractor in version 8.0.0.0

PdfConverter converter = new PdfConverter();
converter.BindPdf(file);
converter.RenderingOptions.BarcodeOptimization = true;
converter.DoConvert();

while (converter.HasNextImage())
{
      using (var ms = new MemoryStream())
      {
          converter.GetNextImage(ms);
          ms.Seek(0L, SeekOrigin.Begin);
          BarCodeReader reader = new BarCodeReader(ms, DecodeType.Code128);
          while (reader.Read())
          {
                var text = reader.GetCodeText();
          }
       }                    
    }

and the brings next question, as per my understanding Aspose.Pdf.Document is new and preferred way to deal with PDF, and Aspose.Pdf.Facades.PdfConverter and Aspose.Pdf.Facades.PdfExtractor is old way to deal with PDF.

So why the code works with old version but not with new version that uses Document class?

@Laksh,

For testing and evaluation of complete features, temporary license for 30 days can be obtained. Get a temporary license, use in your test project and share the feedback. Furthermore Aspose.PDF and Aspose.BarCode are two different and independent APIs. We need to perform some testing in this regard. We will update you soon about our findings.