Issue with generating EAN128 code using Barcode4j for multiple sets of AI and data

1.8k views Asked by At

I'm using barcode4j to generate EAN128 barcode. The barcode I need to generate contains multiple sets of Application Identifiers and data, for example:

(410)000061000034(412)000001101593

The data length for both 410 and 412 is 13 characters. I'm using add checksum mode, so as you can see in above example I only intend to provide 12 characters as the data for each AI and would expect a checksum digit would be calculated and automatically appended.

However by using below code, it does NOT generate the correct code for me:

    dpi = 200;
    // barcode
    objEAN128Bean.setModuleWidth(0.21);
    objEAN128Bean.setHeight(15);
    // objEAN128Bean.setWideFactor(3);
    objEAN128Bean.doQuietZone(true);
    objEAN128Bean.setQuietZone(2);
    // human-readable
    objEAN128Bean.setFontName("Helvetica");
    objEAN128Bean.setFontSize(3);
    // checksum
    objEAN128Bean.setChecksumMode(objCheckSum.CP_ADD);
    BitmapCanvasProvider canvas = new BitmapCanvasProvider(out,
                "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, true, 0);
    objEAN128Bean.generateBarcode(canvas, "410000061000034412000001101593");
    canvas.finish();

It looks like the barcode4j does NOT know where the data of the first AI (410) ends and thus does NOT correctly identify the second set of AI and data.

I found there is a way to do it by using the XML approach specifying sth like:

<template>(410)n12+cd1(412)n12+cd1</template>

I'm just wondering if anyone knows a solution by using the Java bean approach?

Any help and shed of light would be much appreciated!

2

There are 2 answers

1
File_life On BEST ANSWER

Maybe it's too late for this answer but I've solved it just by adding the template to the objEAN128Bean:

objEAN128Bean.setTemplate("(415)n13+(8020)n18+(3902)n10+cd");

and it will bind the string properly.

1
Brimstedt On

I do not know if it is relevant for you, but in Jasper report's barcode4j component, you can start a new application identifier with the \u00f1 character.

"97XXX\u00f1916213514687"

It will give you a barcode like

(97) XXX (91) 6213514687