Hi,
I upgraded barcode from version 2.7 to version 22.8.
I could not find the EAN-128 barcode type in the new version and switched to CODE-128 as per this support entry: https://forum.aspose.com/t/booklandean-and-ean128-barcode-symbology-types-not-available-in-6-2-version/9608
This code worked fine in version 2.7:
BarCodeBuilder bcb = new BarCodeBuilder();
bcb.setSymbology(Symbology.EAN128);
bcb.setCodeText("My barcode test");
bcb.setAutoSize(true);
bcb.setBorderVisible(false);
bcb.setCodeTextVisible(false);
Image image = bcb.generateBarCodeImage();
Assert.assertNotNull(image);
After upgrading to version 22.8 and modifying the code for the new API, I tried this:
BarcodeGenerator bcg = new BarcodeGenerator(EncodeTypes.CODE_128);
bcg.setCodeText("My barcode test");
bcg.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);
bcg.getParameters().getBorder().setVisible(false);
bcg.getParameters().getBarcode().getCodeTextParameters().setLocation(CodeLocation.NONE);
BufferedImage image = bcg.generateBarCodeImage();
Assert.assertNotNull(image);
The new code will throw com.aspose.barcode.BarCodeException: Can’t render barcode: not enough space
It works with a shorter code-text, but that does not help, as our customers expect (and I think rightfully so) to generate the same barcodes that they used to create.
Are there any settings that I missed which will allow me to generate the desired barcode?
PS: I just ran into a very similar problem with the CODE-39-STANDARD type.
@INFINICA,
Thanks for the details.
Please notice, I am able to reproduce the issue as you mentioned with Aspose.BarCode for Java 22.8. I got an error: “com.aspose.barcode.BarCodeException: Can’t render barcode: not enough space” on generating barcode image. I have logged a ticket with an id “BARCODEJAVA-1451” for your issue. We will look into it soon.
Once we have an update on it, we will let you know.
PPS: This problems seems not to be linked to a specific barcode type. So far, I experienced it with CODE-128, DATA-MATRIX, CODE-39-STANDARD, QR.
In all cases, I tried to generate a barcode without specifying the size and with auto-size enabled. Still, I get the “not enough space” message, which does not make sense, or at least is a distinctly unhelpful message.
@INFINICA,
Thanks for sharing your findings.
We have logged it with your existing ticket into our database. The detail might help to evaluate the issue. Once we figure your issue out, we will update you.
AutoSizeMode.NEAREST requires previously set ImageHeight and ImageWidth. In default barcode their values are small. In nomal mode you should use AutoSizeMode.None and manupulate barcode size by XDimension. About differences of sizing modes in BarcodeGenerator you can read here, but the documentation for .Net library version:
In this way it is not a bug, but you should use AutoSizeMode different from None only with ImageHeight and ImageWidth.
BarcodeGenerator bcg = new BarcodeGenerator(EncodeTypes.CODE_128);
bcg.setCodeText("My barcode test");
bcg.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);
bcg.getParameters().getBorder().setVisible(false);
bcg.getParameters().getBarcode().getCodeTextParameters().setLocation(CodeLocation.NONE);
//increase image size to fit barcode
bcg.getParameters().getImageWidth().setPixels(500);
java.awt.image.BufferedImage image = bcg.generateBarCodeImage();
File outputfile = new File("result.png");
ImageIO.write(image, "png", outputfile);