javaformatbarcodezxingbarcode4j

Formatting EAN8 with zxing/barcode4j


I am trying to generate an EAN8-barcode in java. If tried barcode4j (which is free in contrary to the barcodelib), which gives me really good results.

One thing I haven't figured out is to change the width and the height of the barcode in barocde4j. I have solved it by the resolution parameter, which isn't imho that good solution.

What i wanna do is generating everthing in zxing (because i also need QR code), but the result look quite ugly. This is how i generate the barcode:

BitMatrix matrix;
com.google.zxing.Writer writer = new EAN8Writer();
com.google.zxing.BarcodeFormat BarcodeFormat;
matrix = writer.encode(code,BarcodeFormat, width, height);
MatrixToImageWriter.writeToStream(matrix, "JPG", output);

Picture looks with zxing like

zxing

But i wish it would look like barcode4j does it:

barcode4j

regards && tia noircc


Solution

  • On Barcode4J: you can only indirectly control the size of the barcode. If you generate barcodes with the bean method, you have setHeight(double) and setModuleWidth(double) to influence the size:

    EAN8Bean javadoc

    With XML configuration, you can find the possible values here.

    And BTW, I strongly recommend NOT to generate JPEGs for barcode because it's a lossy format which can have an influence on contrast and barcodes live off contrast. Use PNG instead! Furthermore, you might want to read the troubleshooting page since you're generating bitmaps. It can help avoid scanning problems later.