Bar code reader and Barcode Generator not fetching the same Numbers

Hi,

We use Barcode generator to Generate a Integer in the form of Barcode. Please find below code

  Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(pdfStream);

                using (MemoryStream barcodeStream = new MemoryStream())
                {
                    string barcodePrefix = ConfigurationManager.AppSettings["BarcodePrefix"].ToString();
                    using (BarcodeGenerator builder = new BarcodeGenerator(EncodeTypes.Code128, barcodePrefix + docQueueID.ToString()))
                    {
                        builder.Save(barcodeStream, BarCodeImageFormat.Bmp);

                        double pdfPageHeight = pdfDoc.Pages[1].Rect.Height;
                        double pdfPageWidth = pdfDoc.Pages[1].Rect.Width;
                        double marginTop = 45;
                        double marginRight = 10;

                        //Locate the top right corner of the pdf for barcode placement
                        Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(pdfPageWidth - 230 - marginRight, pdfPageHeight - 65 - marginTop, pdfPageWidth - marginRight, pdfPageHeight - marginTop); //Barcode size is 230x65 pts

                        pdfDoc.Pages[1].AddImage(barcodeStream, rect);  //Add barcode to first page of worksheet PDF

Same Barcode when we are reading it is reading as different number.

 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
                    }

Please let us know what is causing this issue.

GeneratorCode.pdf (27.3 KB)
ReaderBarcode.pdf (27.4 KB)

Please find attached is the Generated Barcode and Read barcode. for some reason … both are not matching. Please help in identifying the Issue

@PriyaPraveen,
Thank you for your query.
I have tried to make your code runnable as it got some missing references but could not observe any issue in the reading and writing of barcode from the PDF file. The modified code is attached here for your reference. Please give it a try using the latest versions of Aspose.BarCode and Aspose.Pdf and share the feedback. If your runnable code is different and uses some template file, please share the complete runnable solution with us for our testing. We will use it to reproduce the issue and provide our feedback after detailed analysis.
Sample.txt.zip (1.7 KB)

Code 128 barcode has too weak checksum because it was developed in 1981. Our engine can recognize blurred and distorted barcodes but sometimes it can recognize barcode incorrectly because we check correct recognition by checksum and the checksum can be right on wrong barcodes.

To avoid this you should use barcodes with strong checksum (Reed–Solomon error correction) like pdf417, datamatrix, Aztec or QR codes. In this case if this barcode type is recognized it is recognized correctly.

Thanks Alexander,

can you please help us give the right encode types that can be used? in the suggestion there are pdf417, datamatrix, Aztec or QR codes. can you please help us to identify the specific encode types that can be used.

@PriyaPraveen,
Thank you for writing to Aspose support team again. Well it all depends upon your needs as each barcode has its own pros and cons which need to be considered before selecting any barcode. You may please google this and read the specifications of each type of barcode and its strengths, limitations and common usage etc. For example have a look at the following link where detailed discussion is done about different types of barcodes and their common usage. Move to the section Two Dimensional Barcode Types where all the four types i.e. PDF417, Datamatrix, Aztec and QR codes are discussed. Aspose.Barcode supports all the four types and you may please write back to us if you face any problem while using them.

can you please help us give the right encode types that can be used

QR code has most of features and at this time it is standard of universal barcode. Main disadvantage of QR is only square form.

Datamatrix and pdf417/compact pdf417 can have rectangular form and can used as 1D barcodes but with higher durability. They have slightly less advantages as QR codes but any information can be encode with these types.

Also you can investigate MicroPDF417, MicroQR which have some advantages as decreased required place to mark barcode. However these barcodes require better image quality to detect barcode, but detected barcode will be always with right codetext.

Aztec have the same disadvantages as QR and has no difference for user from pdf417 and Datamatrix.