Unable to Read bar code when pdf has seal

Unable to read PDF Barcode we a seal is present in the PDF Page. TestPDF.pdf (3.4 MB)

Please find the attached PDF. Below is the code we use for checking the barcode.

string inputFileName = Path.GetFileNameWithoutExtension(filePath);
string barcodePrefix = ConfigurationManager.AppSettings[“BarcodePrefix”].ToString();

        FileUtils.CheckFileHasCopied(filePath);

        //Gather PDF Splitting information
        List<PdfSplitInfo> splitInfos = new List<PdfSplitInfo>();
        Document inputDocument = new Aspose.Pdf.Document(filePath);
        for (int pageNo = 1; pageNo <= inputDocument.Pages.Count; pageNo++)
        {
            using (MemoryStream pageStream = new MemoryStream())
            {
                Resolution resolution = new Resolution(300);
                PngDevice pngDevice = new PngDevice(resolution);
                //Convert a particular page and save the image to stream
                pngDevice.Process(inputDocument.Pages[pageNo], pageStream);
                // Set the stream position to the beginning of Stream
                pageStream.Position = 0;
                // Instantiate a BarCodeReader object and set symbology type to recognize
                BarCodeReader barCodeReader = new BarCodeReader(pageStream, DecodeType.Code128);

                // if there is a barcode, then Read method will return true
                string codeText = string.Empty;
                bool isValidBarCode = barCodeReader.Read();
                if (isValidBarCode)
                {
                    codeText = barCodeReader.GetCodeText();
                    isValidBarCode = codeText.StartsWith(barcodePrefix);    //Consider barcodes that start with the BarcodePrefix
                    isValidBarCode = isValidBarCode && (codeText.Length >= (BARCODE_VALID_MIN_LENGTH + barcodePrefix.Length));  //Consider barcodes that have the min-length
                    if (isValidBarCode)
                    {
                        codeText = codeText.Substring(barcodePrefix.Length);    //Strip off the BarcodePrefix to get the DocQueueID
                    }
                }

                barCodeReader.Close();

Any help on this will be appreciated.

@PriyaPraveen,

Thanks for the sample document and sample code segment.

Please provide us image file (e.g .png file), so we could evaluate your issue directly using Aspose.BarCode API and without involving other API (Aspose.PDF).

PNG/ Image files are working as expected. Any way have attached the image too image.jpg (45.0 KB)

Issue is only when in the PDF.

@PriyaPraveen,

If images are working fine and Aspose.BarCode for .NET reads the barcode fine, then the issue might not be with Aspose.BarCode API rather you should check where you extract the image from the PDF document. Even you may try reading the separate image from streams to be read via BarCodeReader. Make sure the image is saved/extracted fine (please debug your code) from the PDF document so Aspose.BarCode could read it as expected.

@Amjad_Sahi ,

Thanks for the Reply!!!

Please note that the Read() method is not returning. Even if it returns with an error we can handle, but system seems to be hanging. our core objective is to read bar code in the PDF. For Some reason system hangs. Please find Previous post for the PDF which is having issue. Can you please help us on that.

Thanks,
Priya

@PriyaPraveen,
We are looking into this issue and will share our feedback soon.

@PriyaPraveen,

After further evaluation of your issue, I am able to reproduce the issue as you mentioned by using your sample code with your template file. I even tried with the separate image file (after saving the PDF to an image file) but to no avail. It looks like Aspose.BarCode does not read barcode when PDF/image has a seal in it. I have logged a ticket with an id “BARCODENET-37225” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

@PriyaPraveen,

We are pleased to inform you that your issue (logged earlier as “BARCODENET-37225”) has bee resolved. We will soon share the Download link to the fixed version/latest release for your requirement.

@Amjad_Sahi, Please let us know when we will be getting latest version for our requirement. As the issue we found was in our production and our users are waiting for the fix.

@PriyaPraveen,

We will get back to you soon with latest updates on it.

We are sorry for any inconvenience caused!

@PriyaPraveen,

The hanging issue should be fixed in the latest version/fix: Aspose.BarCode for .NET 19.6, please try it:
Downloads ---New-Releases-aspose.barcode-for-.net-19.6 .

We have tested tested with images like TestPDF_image_1.png and image.jpg using v19.6 with the following sample code:
e.g
Sample code:

BarCodeReader reader = new BarCodeReader(lOrigBmp);
reader.SetBarCodeReadType(DecodeType.Code128);
while (reader.Read())
{
string lRes = "Type: " + reader.GetCodeType().ToString() + " Angle: " + reader.GetAngle().ToString() + " " + reader.GetCodeText();
MessageBox.Show(lRes);
}
MessageBox.Show("Ok");

it works as expected.

Let us know if you still find this issue.

@Amjad_Sahi,

Thanks a lot for looking into the issue promptly and fixing it with the 19.6 update!

It is working fine and we are able to access the page even when there is seal.

Thanks,
Priya

@PriyaPraveen,

Good to know that your issue is sorted out by the new 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.