How to set barcode width

Dear Support Team,

We try to use Aspose.Barcode.dll to develop application barcode.
We have problem with barcode width it longer. how to reduce width size.

The data in barcode 39 charecters (string _text = “|099400018891900” + “\r” + “010400530169042” + “\r” + “” + “\r” + “0”:wink: when print out 8.5 cm but we need 5 cm.


string _text = “|099400018891900” + “\r” + “010400530169042” + “\r” + “” + “\r” + “0”;
Aspose.BarCode.BarCodeBuilder builder = new Aspose.BarCode.BarCodeBuilder();
builder.CodeText = _text;
builder.CodeLocation = Aspose.BarCode.CodeLocation.Below;
builder.SymbologyType = Aspose.BarCode.Symbology.Code128;
builder.Resolution = new Aspose.BarCode.Resolution(100f, 100f, Aspose.BarCode.ResolutionMode.Graphics);
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.BarHeight = 15;
builder.xDimension = 0.01f;
builder.BarWidthReduction = 0.01f;
builder.WideNarrowRatio = 1f;
builder.AspectRatio = 0.01f;
builder.Margins.Set(2, 2, 2, 0);
MemoryStream imgStream = new MemoryStream();
builder.Save(imgStream, ImageFormat.Png);
Hi Nopparat,

Thank you for your inquiry and sharing sample.

This is to update you that width of the barcode also depends on length of code text as well. The code text that you are using is long. The minimum width of barcode image could be 8cm in case you use margins 0. Furthermore please note that Graphics Unit is Millimeter where 10mm = 1cm.