LP13
LP13

Reputation: 34149

Aspose.Barcode cannot read DecodeType.Code128 barcode

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

Workflow Steps
1>Using Aspose.Barcode 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;
    }

Upvotes: 0

Views: 357

Answers (1)

Ikram.haq
Ikram.haq

Reputation: 116

Unable to reproduce the issue at my end. I used the following sample code snippet to recognize the barcode along with latest version of the API. It is always recommended to use the latest version of the API as it contains new features and improvements.

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();
        }

Further to update you that the same query has been post on Aspose.BarCode support forum. You may please visit the link for details.

I work as developer evangelist at Aspose.

Upvotes: 0

Related Questions