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

Free Support Forum - aspose.com

Control 2D Barcode size

It appears that width/height of the 2D barcode depends on the amount of data used for the barcode. We need the barcode to have fixed width/height. We don't want its size to shrink if there is less data to encode.

How can we set the barcode to a fixed width/height? Specificially, if I need to set the barcode to be 50x50 pixels. How would I do this in code? Please show examples of either C# or VB code. Thanks.


Thank you for considering Aspose.

The barcode label size depends upon a lot of factors that are discussed in below linked technical article.

One of the main factor is the amount of data that you are trying to encode. Be default, the barcode label adjusts it’s size automatically according to the encoded data. But you can force BarCodeBuilder not to shrink or expand barcode size by setting BarCodeBuilder.AutoSize to false.

Please check the below sample source for your reference,

Dim bb As Aspose.BarCode.BarCodeBuilder = New Aspose.BarCode.BarCodeBuilder

'Set the Code text for the barcode

bb.CodeText = “test”

Set the symbology type to Code39Standard

bb.SymbologyType = Aspose.BarCode.Symbology.Code128

'Set AutoSize to False

bb.AutoSize = False

Set GraphicsUnit to Pixel

bb.GraphicsUnit = GraphicsUnit.Pixel

'Set image size

bb.ImageHeight = 50

bb.ImageWidth = 50

In case you have further queries or comments, please feel free to write back.
Thank you

Thanks. I have already tried this approach. However, setting ImageHeight and ImageWidth properties only affects the width and height of the canvas on which barcode is drawn. It has no impact on the size of the barcode at all. If I set ImageHeight and ImageWidth to a large number, I just get a huge white canvas and a small barcode in the center of it.

Please let me know how I can set the size of the barcode image. Specifically the 2D barcodes. Thanks.


For controlling the barcode size (height of the bars and width of label) please refer to the below linked documentation,

Please note again that the barcode size mainly depends upon the data to be encoded. If the data size is large and you are packing it in a smaller image then the resultant barcode can be illegible.


Thanks for your feedback but neither of these approaches allow me to control the barcode size. As you said, the barcode size always varies depending on the amount of data.

I understand that the barcode may not be legible when it's too small. However, we can always pick the right size for our barcodes and make sure that they scan at the selected size. We are embedding 2D barcodes in the top right section of our documents. Since the size of the barcode varies, it ends up jumping up and down, left and right in that section. I would like to select a fixed size that's big enough for the largest amount of data and use it for all barcodes. Is this possible?


Thank you for your understanding.

If the amount of data can vary then it isn’t possible to keep the barcode at fixed size. Please share the barcode symbology that you are currently using and the maximum data size so we can check this for you.