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

Free Support Forum - aspose.com

Barcode Image query

i want to know if i set true in setAutoSize() , than can i still manipulate the height and margin of the barcode

Hi Kiran,

Thanks for considering Aspose.

I tried generating barcodes within the specified height and width using Code39 symbology, but I am afraid, the size of barcode image exceeds the size limits.

Could you please consider Code128 symbology. I was able to generate barcodes according to all 4 size specifications. Please see the attached java file for generating barcodes. Code128 images are also attached.

The sample code attached also recognizes the barcode for verification that barcode was generated correctly. You need a valid temporary or permanent license to do the recognition part. Please refer to http://www.aspose.com/corporate/purchase/temporary-license.aspx for instructions about getting a free 30 days temporary license.

Hi Saqib,

Thanks a lot for your help,but the thing is that as per our requirement type of symbology for generating the barcode is decided at run time and the user can select any type of symbology say for example either code39 or code128 or code11 or anything else.Hence for different symbologies it will be bit difficult for us to set different codeTextFont and barHeight.

We have purchased the license and I tried generating barcode of symbology 128 but even if i set different height and width for the barcode image,it is still generating barcodes of same height and width.

Below is the code snippet that i am trying but still not getting the desired result

codeBuilder.setAutoSize(true);
codeBuilder.setSymbology(Symbology.CODE128);
codeBuilder.setCodeText("41");
codeBuilder.setGraphicsUnit(GraphicsUnit.MILIMETER);
Margins margins = new Margins();
margins.setLeft(6f);
margins.setRight(6f);
margins.setTop(6f);
margins.setBottom(6f);
codeBuilder.setMargins(margins);
codeBuilder.setXDimension(0.3f);
codeBuilder.setYDimension(0.3f);
codeBuilder.setHeight(barCodeHeight);
codeBuilder.setWidth(barCodeWidth);
codeBuilder.save(barcodeImagePath);

try{
BarCodeReader rd = new BarCodeReader(Toolkit.getDefaultToolkit().getImage(barcodeImagePath));
while(rd.read()){
System.out.println("CodeText: " + rd.getCodeText().toString());
System.out.println("CodeText: " + rd.getReadType());
}
}catch(Exception ex){
System.out.println("Error in recognising barcode :"+ex);
}

/** this are the set of height and widths that needs to be set depending on the label size on which the barcode is to be printed **/
barCodeHeight = 28.0f;
barCodeWidth = 48.0f;
&&
barCodeHeight = 13.0f;
barCodeWidth = 38.0f;
&&
barCodeHeight = 38.0f;
barCodeWidth = 58.0f;
&&
barCodeHeight = 23.0f;
barCodeWidth = 48.0f;

Hi Saqib,
I tried your code for CODE11 and CODABAR,but in that case margins are not coming properly.

Thanks
Kiran