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

Free Support Forum - aspose.com

BARCODE getCustomSizeBarCodeImage

Hello, i have to generate un BarCode : BarCodeBuilder builder = new BarCodeBuilder(); builder.setSymbologyType(“Code128”); builder.setCodeLocation(CodeLocation.None); builder.setCodeText(“Text exemple”); builder.setGraphicsUnit(GraphicsUnit.Pixel); builder.getMargins().set(0); BufferedImage img2 = builder.getCustomSizeBarCodeImage(new Dimension( 50, 50 ), false); But it gives this error “Customize wanted is outside the limits” How can one specify the dimension and what is the value that should not be exceeded ?? If I want to change it GraphicsUnit GraphicsUnit.Millimeter What is the value of the height and width that should not be exceeded ? How does this methode work fonctiongetCustomSizeBarCodeImage ? thank you for your help


I posted it to Aspose.BarCode. I’m stuck, I hope I have an answer before tonight.

thank you for your reply


What value of width and height that should not be exceeded for genere Code 128? And for QR?

Thank you in advance

I have this error :

class com.aspose.barcode.BarCodeException: Custom size wanted is outside the limits.

BufferedImage bufferedImage = builder.getOnlyBarCodeImage ();
BufferedImage image = builder.getCustomSizeBarCodeImage(new Dimension(bufferedImage.getWidth() *50, bufferedImage.getHeight();50), false);

GraphicsUnit  , what the calculation of dimension ?? 

thanks for your help

Hi Jihane,

Thank you for your inquiry.

This is to update you that you can adjust barcode image size and can set unit of the barcode image through code. There is no implicit/default restriction on maximum height & width except if there is any in the specification e.g. Code 128.

Furthermore we are unable to reproduce the issue at our end. We are attaching the sample output barcode image and sample code for your reference.

// Generate the bar code
BarCodeBuilder builder = new BarCodeBuilder();
// Set symbology type
// Set the code text
// Set the code text location
// Set graphics unit
// Set margins
// Get BufferedImage with exact bar code only
java.awt.image.BufferedImage img = builder.getOnlyBarCodeImage();
// Allows to set size for whole picture with bar code inside
java.awt.image.BufferedImage tt = builder.getCustomSizeBarCodeImage(new java.awt.Dimension(img.getWidth() * 50, img.getHeight() * 50), false);
// Saving the buffered image
java.io.File outputfile = new java.io.File("custombarcode.png");
javax.imageio.ImageIO.write(tt, "png", outputfile);

Follow the links for details on custom width, barcode image unit size etc:

Hope that above information helps you to generate the barcode image of custom size. Feel free to contact us in case of any query or comments along with your sample code project demonstrating the issue and details about what is expected as output.

i have this error When you run this code :

class com.aspose.barcode.BarCodeException: Custom size wanted is outside the limits.

com.aspose.barcode.j.a(Unknown Source)
com.aspose.barcode.j.a(Unknown Source)
com.aspose.barcode.j.a(Unknown Source)
com.aspose.barcode.BarCodeBuilder.a(Unknown Source)
com.aspose.barcode.BarCodeBuilder.getCustomSizeBarCodeImage(Unknown Source)

I use Aspose.BarCode : Version 6.8.0

Waiting for your response as soon as possible, thank you very much .

Hi Jihane,

Thank you for writing us back.

This is to update you that it is always recommended to use the latest version. Please download the latest version Aspose.BarCode for Java v.16.11 and try to reproduce the issue at your end. In case of any issue, forward us the details. We will look into it and update you accordingly.

Hi Jihane,

We have observed your last inquiry. It seems to be without text. Should we ignore it or you may please share your inquiry.