简体   繁体   English

使用Barcode4j为多组AI和数据生成EAN128代码的问题

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

I'm using barcode4j to generate EAN128 barcode. 我正在使用barcode4j生成EAN128条形码。 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 . 410412的数据长度为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. 我正在使用添加校验和模式,因此您可以在上面的示例中看到我只打算提供12个字符作为每个AI的数据,并且期望校验和数字将被计算并自动附加。

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. 看起来barcode4j不知道第一AI (410)的数据在何处结束,因此不能正确识别第二组AI和数据。

I found there is a way to do it by using the XML approach specifying sth like: 我发现有一种方法可以通过使用指定类似的XML方法来实现:

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

I'm just wondering if anyone knows a solution by using the Java bean approach? 我只是想知道是否有人通过使用Java bean方法知道解决方案?

Any help and shed of light would be much appreciated! 任何帮助和光线将非常感谢!

Maybe it's too late for this answer but I've solved it just by adding the template to the objEAN128Bean : 也许这个答案为时已晚,但我只是通过将模板添加到objEAN128Bean来解决它:

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

and it will bind the string properly. 它会正确绑定字符串。

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 character. 我不知道它是否与您相关,但在Jasper报告的barcode4j组件中,您可以使用字符启动一个新的应用程序标识符。

"97XXX\u00f1916213514687"

It will give you a barcode like 它会给你一个像这样的条形码

(97) XXX (91) 6213514687

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM