We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

CodeText is blurred

Greetings Aspose support.


We have a slight problem with CodeText - the quality of the text is really poor (comparing to the barcode image).

See attached picture for example.

The code we use to generate the barcode:

BarCodeBuilder barcodeBuilder = new BarCodeBuilder();
barcodeBuilder.GraphicsUnit = GraphicsUnit.Pixel;
barcodeBuilder.CodeText = codeText
barcodeBuilder.CodeTextAlignment = StringAlignment.Center;
barcodeBuilder.CodeTextEncoding = Encoding.Unicode;
barcodeBuilder.AutoSize = true;
barcodeBuilder.BarHeight = 35;
barcodeBuilder.ImageWidth = offsetX;
barcodeBuilder.ImageHeight = offsetY;
barcodeBuilder.CaptionAbove = new Caption();
var barcodeImage = barcodeBuilder.GenerateBarCodeImage();

Is there a property, that can help improve the resolution of CodeText?

Thank you!

Kind regards,
Katja
Hi Katja,

Thank you for your inquiry and sharing details.

We have investigated the issue at our end. It was found that resolution setting is missing in your code snippet due to which image quality is poor. Please add the following line in your code and try again at you end. In case the issue persists, forward us the complete code along with details to reproduce the issue.

CODE:
barcodeBuilder.Resolution = new Aspose.BarCode.Resolution(300, 300, Aspose.BarCode.ResolutionMode.Graphics);

Hello.


Changing the resolution does not change the quality of the text, only it’s size (which is not what we want).

Here is the code we use to print the barcode:

MemoryStream outputStream = new MemoryStream();
Aspose.Words.Document pdfDoc = new Aspose.Words.Document();

DocumentBuilder docBuilder = new DocumentBuilder(pdfDoc);

BarCodeBuilder barcodeBuilder = new BarCodeBuilder();
barcodeBuilder.GraphicsUnit = GraphicsUnit.Pixel;
barcodeBuilder.CodeText = barcodeText;
barcodeBuilder.CodeTextAlignment = StringAlignment.Center;
barcodeBuilder.CodeTextEncoding = Encoding.Unicode;
barcodeBuilder.AutoSize = true;
barcodeBuilder.BarHeight = 35;
barcodeBuilder.ImageWidth = offsetX-2;
barcodeBuilder.ImageHeight = offsetY-5;
barcodeBuilder.Resolution = new Aspose.BarCode.Resolution(150, 350, Aspose.BarCode.ResolutionMode.Graphics);
barcodeBuilder.CaptionAbove = new Caption();
var barcodeImage = barcodeBuilder.GenerateBarCodeImage();

docBuilder.InsertImage(barcodeImage,
Aspose.Words.Drawing.RelativeHorizontalPosition.Page,
xPosition,
Aspose.Words.Drawing.RelativeVerticalPosition.Page,
yPosition,
offsetX - 3,
offsetY - 15,
Aspose.Words.Drawing.WrapType.Through);

var barcodeLogo = new Bitmap(new MemoryStream(barcodeLabel));
var scale = GetScale(barcodeLogo, 30, 15);
docBuilder.InsertImage(barcodeLogo,
Aspose.Words.Drawing.RelativeHorizontalPosition.Page,
xLogoPosition + (barcodeImage.Width - scale.Item1)/2,
Aspose.Words.Drawing.RelativeVerticalPosition.Page,
yLogoPosition,
scale.Item1,
scale.Item2,
Aspose.Words.Drawing.WrapType.Through);

pdfDoc.Save(outputStream, Aspose.Words.SaveFormat.Pdf);

I will also attach the before and after pictures (meaning, before and after I added your sugested line of code), so you can see that the text only changes size and not the actual quality, as I requested before. The text is very pixelated.

King regards,
Katja
Hi Katja,

Thank you for writing us back.

We have requested you to please share the complete code; the code snippet you have shared is not complete. However, we have changed your code a bit to investigate the issue. It was found that you are using Aspose.BarCode in combination with Aspose.Words to generate the PDF. The code snippet we used is given below for your reference. While investigation we saved the barcode image on the disk. It was found that Aspose.BarCode is working fine. The issue is while you are trying to use the barcode image stream to generate PDF.

You are trying to embed a stretched barcode image into the PDF file due to which bad quality of barcode image is seen in the PDF file. Generated barcode image and PDF file is attached for your reference.

It is request to please forward us a sample .Net project having complete code to analyze the issue. We will forward the sample project to Aspose.Words support team for further investigation.

CODE:

string barcodeText = "MA150001251";
System.IO.MemoryStream outputStream = new System.IO.MemoryStream();
Aspose.Words.Document pdfDoc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder docBuilder = new Aspose.Words.DocumentBuilder(pdfDoc);
Aspose.BarCode.BarCodeBuilder barcodeBuilder = new Aspose.BarCode.BarCodeBuilder();
barcodeBuilder.GraphicsUnit = GraphicsUnit.Pixel;
barcodeBuilder.CodeText = barcodeText;
barcodeBuilder.CodeTextAlignment = StringAlignment.Center;
barcodeBuilder.CodeTextEncoding = Encoding.Unicode;
barcodeBuilder.AutoSize = true;
barcodeBuilder.BarHeight = 35;
barcodeBuilder.ImageWidth = 500; //offsetX - 2;
barcodeBuilder.ImageHeight = 200; // offsetY - 5;
barcodeBuilder.Resolution = new Aspose.BarCode.Resolution(150, 350, Aspose.BarCode.ResolutionMode.Graphics);
barcodeBuilder.CaptionAbove = new Aspose.BarCode.Caption();
var barcodeImage = barcodeBuilder.GenerateBarCodeImage();
barcodeBuilder.Save(@"test_caption_Code128.png", Aspose.BarCode.BarCodeImageFormat.Png);
docBuilder.InsertImage(barcodeImage,
Aspose.Words.Drawing.RelativeHorizontalPosition.Page,
30,
Aspose.Words.Drawing.RelativeVerticalPosition.Page,
3,
100,
100,
Aspose.Words.Drawing.WrapType.Through);
pdfDoc.Save(@"test_caption_Code128.pdf", Aspose.Words.SaveFormat.Pdf);

Was this ever resolved? I’m having the same issue. Increasing the barcode resolution doesn’t resolve the poor quality of the caption.

@primepay,

As mentioned in my previous reply that issue is not with Aspose.BarCode as barcode APIs are generating correct image. The issue raises when barcode image stream is used to generate PDF.

It is again request to please forward us a sample .Net project having complete code to analyze the issue. We will forward the sample project to Aspose.Words support team for further investigation.

Greetings Aspose support.

We are not saying that the generated barcode is not correct. It is correct, and the barcode image is perfect, as you can check by zooming in. The barcode itself is clear no matter how much you zoom in. The same can not be said for the CodeText - the text that can ussualy be found bellow the barcode. Will attach photo for reference as to what I am trying to tell you. The issue is in the red square (on the image). As you can see, when you zoom in to the barcode, the barcode itself is fine - the text is blurry. And that blurry text is the issue, as clients have trouble reading the barcode.

I will attach a .cs file with the code that you will need to reproduce the issue. Again, the issue is not whether the barcode is correct or not - it is about the quality of the text.

Kind regards,

Katja

Aspose_BarCode.zip (34.8 KB)

@katja.suvajac,

We have investigated the issue at our end. There could be many reasons for this issue:

  • The blur effect is due to low/different DPI values for the barcode image.
  • Bars are just straight lines without any anti-aliasing. Any picture viewer will zoom it without blur. On the other hand the text is not straight and has anti-aliasing. So zooming it will produce the blur effect.
  • The image has been scaled when generating PDF file, means barcode image was generated with low resolution while it has been scaled before inserting it to PDF file.

You can overcome this issue by increasing image resolution before inserting barcode into PDF or generate a high resolution barcode image.

Hope the above information helps. Feel free to contact us in case of any further query or comments.