Cannot read barcode when Aspose.Words document is saved as PDF

When I save an ASPOSE.Words document with barcode as PDF and try to read barcode image from it using Aspose.BarcodeRecognition.BarcodeReader object, it cannot read or find the barcode text. If I save the document to DOCX format and then save the document as PDF in MS Word, I can read the barcode. The code I am using is given below:


Document coversheet = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(coversheet);

docBuilder.Font.Size = 16;
docBuilder.Font.Bold = true;

docBuilder.InsertBreak(BreakType.ParagraphBreak);
docBuilder.InsertBreak(BreakType.ParagraphBreak);
docBuilder.InsertBreak(BreakType.ParagraphBreak);

docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
docBuilder.Writeln("Comments: " + Comments);
docBuilder.Writeln("Generated By: " + HttpContext.Current.User.Identity.Name.ToString());

BarCodeBuilder barcode = new BarCodeBuilder();
barcode.SymbologyType = Symbology.DataMatrix;
barcode.DataMatrixEncodeMode = DataMatrixEncodeMode.ASCII;
barcode.ImageQuality = ImageQualityMode.AntiAlias;
barcode.CodeText = barcodeText;
barcode.CodeLocation = CodeLocation.None;
barcode.GenerateBarCodeImage();
docBuilder.InsertImage(barcode.BarCodeImage);

MemoryStream msDoc = new MemoryStream();
coversheet.Save(msDoc, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Pdf));

coversheet = null;
Session["DOC_BYTES"] = msDoc;
Session["DOC_NAME"] = "Test.pdf";
System.Threading.Thread.Sleep(1000);
Response.Redirect("ResourceDownload.aspx?IsDlg=1");

I am using Aspose.Words version 4.5.0.04.5.0.0, Aspose.BarCodeRecognition version 4.5.0.04.5.0.0, and Aspose.Barcode version 4.5.0.04.5.0.0.

I tried using Aspose.Barcode.dll v 4.1.0.0 and Aspose.Barcode.Recognition.dll v 4.1.0.0 and everything is working. Looks like there is a bug in the DLL.

Hi Nauman,

Thanks for your inquiry. It is perfect that you managed to achieve what you were looking for. Moreover, I feel your query is more related to Aspose.BarCode, I will move your request in Aspose. BarCode forum. My colleagues from Aspose. BarCode component team will answer you shortly.

Best Regards,

Hi Nauman,


Please accept our apologies for your inconvenience.

I am a representative of Aspose.BarCode product family, and I would like to inform you that we have recently published the next version of Aspose.BarCode for .NET (Latest Version). In case your problem persists with the latest assemblies (link shared above) then please provide the CodeText string that you are encoding with DataMatrix symbology, so we may evaluate the problem cause at our end.

Thank you for your co-operation.

Regards,

I tried using v4.7.0 of Aspose.Pdf.Kit, Aspose.Barcode, Aspose.BarcodeRecognition, and the latest version of Aspose.Words but have the same issue. I can read the barcode using Aspose.Barcode.Recognition v4.1 ONLY when the coversheet is printed from MS Word. It fails if I save the coversheet as PDF, print it, and scan the whole document. The barcode text format is ABC#CDE#DEF#Document Name#Date#comments.

Hi Nauman,


Thank you for your feedback.

I have logged an investigative ticket (BARCODENET-33194) in our bug tracking system to look further into this matter. The ticket has also been attached to your request for tracking purposes. As soon as this issue gets resolved, you will be notified via this forum thread.

For now, if you want to avoid this situation then please generate the barcode with out specifying the ImageQuality for BarCodeBuilder. Please check the source code snippet as given below and give it try at your end.

C#

BarCodeBuilder barcode = new BarCodeBuilder();
barcode.SymbologyType = Symbology.DataMatrix;
barcode.DataMatrixEncodeMode = DataMatrixEncodeMode.ASCII;

// Problem only occurs if ImageQuality is set to AntiAlias
// barcode.ImageQuality = ImageQualityMode.AntiAlias;

barcode.CodeText = sometext;
barcode.CodeLocation = CodeLocation.None;
var bitmap = barcode.GenerateBarCodeImage();
..

Please accept our apologies for your inconvenience.
Regards,

Any update on this? Please let me know.

Hi Nauman,


Thank you for your patience.

We have completed our investigation on the ticket logged earlier as BARCODENET-33194. We have concluded, if AntiAlias property is set for BarCodeBuilder then a shadow is produced on the barcode image that is equivalent to 0.6f xDimension. That makes the image noisy and is the main reason for recognition failure.

Above said behavior can not be changed, therefore development team has marked the ticket’s status as “Won’t Fix”. Although you still can use the AntiAlias property. You need to manually set the xDimension great then 0.6f in order to keep the resultant image fairly recognizable. Please check the below source code for your reference.

C#

BarCodeBuilder barcode = new BarCodeBuilder();
barcode.SymbologyType = Symbology.DataMatrix;
barcode.DataMatrixEncodeMode = DataMatrixEncodeMode.ASCII;
barcode.ImageQuality = ImageQualityMode.AntiAlias;

barcode.xDimension = 0.8f;

barcode.CodeText = “AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz”;
barcode.CodeLocation = CodeLocation.None;
var bitmap = barcode.GenerateBarCodeImage();

BarCodeReader reader = new BarCodeReader(bitmap, BarCodeReadType.AllSupportedTypes);
reader.Read();
Console.WriteLine(reader.GetCodeText())

Please free to write back in case you have further inquiries or comments.
Regards,

Thanks for the update. I am also having difficulty reading the barcode when I scan a page with barcode to a 200 DPI PDF file. If I change the DPI to 300 DPI, it works. I am using the following code. Please advise.

BarCodeBuilder barcode = new BarCodeBuilder();
barcode.SymbologyType = Symbology.DataMatrix;
barcode.DataMatrixEncodeMode = DataMatrixEncodeMode.ASCII;
barcode.ImageQuality = ImageQualityMode.AntiAlias;
barcode.xDimension = 0.8f;
barcode.CodeText = barcodeText;
barcode.CodeLocation = CodeLocation.None;v

Hi Nauman,


Thank you for writing back.

We have recently published Aspose.BarCode for .NET (Latest Version). I would request you to please give the latest assemblies a try and check if they fulfills the requirement for the recognition purpose. In case your problem persists, please share an image that was scanned with 200 DPI, and fails the recognition process.

Regards,

I can only read few barcodes at 200 DPI when using v4.1.0.0 of Aspose.Barcode.Recognition.dll for .NET Framework 3.5. Attached are the barcode at 200 DPI. Only one of them works. Please see the images in the attached file.

Thanks,

Nauman.

Hi Nauman,


Thank you for sharing your samples.

I have tested the samples with the latest version of Aspose.BarCode for .NET v4.8.0, I am afraid that only one barcode symbol (Barcode200DPIb.png) gets scanned. For further investigation and correction, I have logged a ticket in our defect database and attached it you your request for tracking purposes. As soon as development team completes their analysis, I will share the results here for your kind reference.

We are sorry for your inconvenience.
Regards,

The issues you have found earlier (filed as BARCODENET-33257) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.