Understanding X / Y Dimension In Relation To Generated Barcode Quality

Hello,


My requirement is to produce a barcode on some shipping labels that needs to follow certain sizing guidelines. Along with the size guidelines, the barcode must print with a high quality (i.e. sharp black and white bars).

For context, the barcode symbology is Code128. I have two barcodes to produce. One barcode will have 17 characters and be 55m wide by 25m high. An example is ‘10008688694055001’. The second barcode will have three characters (e.g. ‘035’) and be 25m wide by 25m high.

Through several days of trial and error, I am starting to get close to example labels I have been sent in terms of the size and print quality.

My code after such trial and error looks like this:

BarCodeBuilder builder = new BarCodeBuilder();
builder.setSymbologyType(Symbology.Code128);
builder.setCodeLocation(CodeLocation.None);
builder.setCodeText(data);
builder.setxDimension(1f);
builder.setyDimension(3.33f);
builder.setBarHeight(60f);
builder.getMargins().set(0, 0, 0, 0);
return builder.getBarCodeImage();

Finally with these settings, the print quality of the first (bigger) barcode looks OK. Although the barcode generated is slightly wider than the requirement (57m vs 55m), I think it will pass the testing.

The second barcode is almost the perfect size, but the print quality just isn’t as sharp as it should be. It’s not terrible, but the lines aren’t as thick and sharp as I would expect. Changing the x / y / height dimensions I can see clearly has an affect to not only the size, but crucially the barcode quality when it prints.

Can someone help explain (or point me in the direction of any articles) that explain exactly what x/y dimensions and bar height mean and how they work in relation to one another? My feeling is I could eventually stumble upon the right set of values for the smaller barcode to ensure the print quality is as expected - but hoping it will be quicker if I actually understand what these things are doing so can be more “scientific” in the values I am setting!

Thanks for any help.

Hi Marcus,

When you set GraphicsUnit to millimeter or inch, you must set resolution in this case. You can either use pixel as graphics unit or set resolution (with height and width) if you want to use millimeter to get accurate results.

In short, you can use setAutoSize, setGraphicsUnits, setResolution, setImageWidth and setImageHeight methods to set auto size to false, and set graphics units, resolution, width and height respectively. Once these values are set, you will see the correct result.

Please also keep the following calculations in mind when setting the size.

inches = pixels / dpi
pixel = inches * dpi
1 centimeter = 0.393700787 inches
1 centimeter = 10 millimeters therefore 1 millimeter = 0.0393700787 inches
pixel = cm 0.393700787 dpi
8 Millimeters = 8 * 0.0393700787 inches = 0.1181102361 inches

Best Regards,