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

Free Support Forum - aspose.com

How to force CodeText/Caption on Top of barcode to span the entire width of barcode

I am currently testing Aspose.Barcode to generate barcode of 19 digit number. Following is the code that I am trying:

using (BarCodeGenerator generator = new BarCodeGenerator(Aspose.BarCode.Generation.EncodeTypes.Code128, “7894213227000000000”))

                                       generator.Checksum.Enable = EnableChecksum.Default;
                                        generator.BarHeight.Pixels = 60f; 
                                        generator.Margins.Bottom.Pixels = 0;
                                        generator.Margins.Top.Pixels = 0;
                                        generator.Margins.Left.Pixels = 0;
                                        generator.Margins.Right.Pixels = 0;
                                        generator.CodeText = suffixedLoanNumber;
                                        generator.CodeTextStyle.Font.FamilyName = "Arial";  
                                        generator.CodeTextStyle.Font.Style = FontStyle.Bold; 
                                        generator.CodeTextStyle.Font.Size.Point = 25;  
                                        generator.CodeTextStyle.Alignment = StringAlignment.Center;
                                        generator.ForeColor = System.Drawing.Color.Black;
                                        generator.BackColor = System.Drawing.Color.White;
                                        generator.Resolution = 300f;
                                        generator.CodeTextStyle.Location = CodeLocation.Above;
                                        var bitmapImage  = generator.GenerateBarCodeImage();
                                        using(MemoryStream ms = new MemoryStream())
                                            bitmapImage.Save(ms, ImageFormat.Bmp);
                                            barcodeImage = ms.ToArray();


Barcode is generating correctly but I want the caption/Code text to start from left and span the entire width of the barcode width.
I have tried left alignment, center and right. Increasing the font size increases the height of the characters. Is there any way to even space out the digits in that number?Capture.PNG (3.5 KB)


I have searched the documentation but no such option is found which can be used to span the caption over the entire width of barcode. 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.