.Net Barcode - Datamatrix angle

I am trying to get the angle of a datamatrix in a PDF. GetAngle() always returns “0” irrespective of the angle of the barcode. Is this meant to work?

@anilr,

We have investigated the issue at our end. Initial investigation shows that the issue persists the issue has been logged into our system with ID BARCODENET-36773 for further investigation. We will update you here once there is some information or a fix version available in this regard.

@anilr,

We have further looked into this issue. It was found that there is no issue with the API. GetAngle() method is working fine. GetAngle() method works when it is called after calling BarCodeReader.Read() method. In this way API completes the recognition process and have angle information. Following is the correct way:

CODE:

BarCodeReader reader = new BarCodeReader(Filename);
reader.SetBarCodeReadType(DecodeType.DataMatrix);
while (reader.Read())
{
     string lRes = "Type: " + reader.GetCodeType().ToString() + " Angle: " + reader.GetAngle().ToString() + " " + reader.GetCodeText();
 Console.WriteLine(lRes);
}

We are sorry for the inconvenience. Please feel free to contact us in case of any query or comments.

Note I used the following code

BarCodeReader CorumBarCodeReader = null;

CorumBarCodeReader = new BarCodeReader(BCImageStream, DecodeType.DataMatrix);
CorumBarCodeReader.RecognitionMode = RecognitionMode.MaxBarCodes;

CorumBarCodeReader.ManualHints = ManualHint.IncorrectBarcodes

while (CorumBarCodeReader.Read())
{
result = CorumBarCodeReader.GetCodeText();
decodedMessages.Items.Add("");
decodedMessages.Items.Add(Path.GetFileName(FileName));
decodedMessages.Items.Add(“Ang:\t” + CorumBarCodeReader.GetAngle());
}

@anilr,

We have tried to reproduce the issue at our end. Initial investigation shows that issue persists. Aspose.BarCode is able to recognize only one out of three barcodes from the sample PDF file. The issue has been logged into our system with ID BARCODENET-36786 for further investigation. We will update you here once there is some information or a fix version available in this regard.

We are able to recognize the barcode as:

Codetext found: TAJFJA;G;EAHIGI]]A;F, 
Symbology: DataMatrix
Angle: 4.184916

Thanks. The decoded string is accurate but I do not ever get a non zero angle. Can you share the source code snippet you used to get the angle?

@anilr,

Following is the sample code snippet that we have used to read the barcode from sample PDF file.

CODE:

using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"Corum-18-56-10 2018_01_12_18_55_25.pdf"))
        {
            int pageCount = pdfDocument.Pages.Count;
            for (var iPDFpageCunt = 1; iPDFpageCunt <= pageCount; iPDFpageCunt++)
            {
                using (System.IO.MemoryStream imageStream = new System.IO.MemoryStream())
                {
                    var resolution = new Aspose.Pdf.Devices.Resolution(300);
                    Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution);
                    pngDevice.Process(pdfDocument.Pages[iPDFpageCunt], imageStream);

                    using (Aspose.BarCode.BarCodeRecognition.BarCodeReader barcodeReader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream, Aspose.BarCode.BarCodeRecognition.DecodeType.AllSupportedTypes)) 
                    {
                        while (barcodeReader.Read())
                        {
                            Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType().ToString());
                            float fVal = barcodeReader.GetAngle();
                            Console.WriteLine("Angle: " + fVal.ToString());
                        }
                    }
                }   
            }

Thank you Ikram for your help to date which is much appreciated. What I discovered was that if I increase the scanning resolution to 300 DPI then I can actually detect the smaller datamatrix barcodes in the PDF.

So the strategy I decided to pursue is:

  1. Set the scanner to scan at 300 DPI and get the source PDF
  2. Detect barcodes in the source PDF
  3. Save the source PDF as a lower resolution PDF.

Once I detect the barcode[s] then I only need to archive the PDF at a human readable resolution to save on disk storage space.

What is the best way of achieving (3)? I don’t see any API at the Document Class level to save a PDF at a particular DPI.

Many thanks.

@anilr,

Thank you for your feedback. One way is that you can compress PDF file and then archive the PDF file on the disk. For details on how PDF document can be resized using Aspose.Pdf is given at Optimize PDF Document.

Any idea why v18.1.0 can’t read this barcode?

I’ve tried MaxQuality recognition mode.

2018_01_24_18_29_06.pdf (186.3 KB)

@anilr,

We are able to recognize the barcode. Sample code snippet along with output is given below for your reference.

CODE:

        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"2018_01_24_18_29_06.pdf");
        int pageCount = pdfDocument.Pages.Count;

        for (var i = 1; i <= pageCount; i++)
        {
            var converter = new Aspose.Pdf.Facades.PdfConverter();
            converter.BindPdf(@"2018_01_24_18_29_06.pdf");
            converter.StartPage = i;
            converter.EndPage = i;
            converter.DoConvert();

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            converter.GetNextImage(stream, System.Drawing.Imaging.ImageFormat.Jpeg, 300);
            //using (Aspose.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCodeRecognition.BarCodeReader(stream, Aspose.BarCodeRecognition.BarCodeReadType.QR))
            using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(stream))
            {
                
                while (reader.Read())
                {
                    Console.WriteLine("Page#" + i + " -- Symbol:" + reader.GetCodeType() + " Code :" + reader.GetCodeText());
                }
            }
            converter.Close();
            converter.Dispose();
        }

OUTPUT:

Page#1 -- Symbol:Code128 Code :1j.'Q&KA)A&E5+*

Hi Ikaram,

Not sure if your analysis applied to the doc attached. There are no QR Codes in that PDF. There is one datamatrix barcode.

Thanks

Anil

@anilr,

Surely we have analysed the same PDF document (2018_01_24_18_29_06.pdf) which was shared by you. First page of this PDF document contains two barcodes. Aspose.BarCode is able to recognize the only one barcode out of two. The issue has been logged into our system with ID BARCODENET-36794 for further investigation. We will update you here once there is some information or a fix version available in this regard.

The issues you have found earlier (filed as BARCODENET-36786) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by muhammadahmad