Printing
Printing
Printer-oriented barcode generation requires control over physical dimensions, raster resolution, and rendering behavior.
Set resolution and physical dimensions
generator.getParameters().setResolution(300.0f);
generator.getParameters().getBarcode().getXDimension()
.setMillimeters(0.33f);
generator.getParameters().getBarcode().getBarHeight()
.setMillimeters(18.0f);
Resolution determines how physical units are converted to pixels. At a higher DPI, the same physical X-dimension is represented by more pixels. Setting DPI does not add detail when every dimension is already fixed in pixels.
The dimensions in an example are not universal print defaults. Verify them against the applicable barcode application specification, printer resolution, substrate, ink spread, and scanner distance.
Configure wide-to-narrow ratio
Some linear symbologies use narrow and wide elements.
generator.getParameters().getBarcode().setWideNarrowRatio(2.5f);
Use a ratio supported by the selected symbology and printing process. See the Code 39 standard overview.
Configure anti-aliasing
generator.getParameters().setUseAntiAlias(false);
Disabling anti-aliasing keeps raster module edges crisp. Enabling it can produce smoother visual edges but may introduce intermediate colors around very small bars or modules. Test both the printed result and the target scanner.
For thermal printers, calculate physical dimensions for the actual device resolution, such as 203 or 300 DPI, rather than resizing a previously rendered bitmap.
Complete example
set