Free Support Forum - aspose.com

BarCodeBuilder 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

Hi,


As you are using Aspose.BarCode APIs, so you have posted your query in the wrong forum. I am now moving your thread to respective forum and one of my fellow colleagues from Aspose.BarCode team will help you soon there.

Thank you.
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
builder.setSymbologyType(com.aspose.barcode.Symbology.Code128);
// Set the code text
builder.setCodeText("12345");
// Set the code text location
builder.setCodeLocation(CodeLocation.None);
// Set graphics unit
builder.setGraphicsUnit(com.aspose.barcode.GraphicsUnit.Millimeter);
// Set margins
builder.getMargins().set(0);
// 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.