简体   繁体   English

Barcode4J pdf417模块出现错误

[英]Barcode4J pdf417 module is giving error

I am trying to convert binary data to pdf417 barcode using pdf417bean class of barcode4J. 我正在尝试使用条形码4J的pdf417bean类将二进制数据转换为pdf417条形码。 But it is giving me following error 但这给了我以下错误

java.lang.IllegalArgumentException: Non-encodable character detected: Í (Unicode: 205)
    org.krysalis.barcode4j.impl.pdf417.PDF417HighLevelEncoder.determineConsecutiveBinaryCount(PDF417HighLevelEncoder.java:468)
    org.krysalis.barcode4j.impl.pdf417.PDF417HighLevelEncoder.encodeHighLevel(PDF417HighLevelEncoder.java:108)
    org.krysalis.barcode4j.impl.pdf417.PDF417LogicImpl.generateBarcodeLogic(PDF417LogicImpl.java:193)
    org.krysalis.barcode4j.impl.pdf417.PDF417Bean.generateBarcode(PDF417Bean.java:79)
    com.pb.iop.labelgen.impl.BarcodeService.generateBarcodecodePDF417(BarcodeService.java:244)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:165)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:276)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1171)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1103)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1053)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1043)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:477)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Here's a part of codebase I am using 这是我正在使用的代码库的一部分

        PDF417Bean bean = new PDF417Bean();

        bean.doQuietZone(true);
        bean.setModuleWidth(UnitConv.in2mm(moduleWidthInches));
        bean.setQuietZone(UnitConv.in2mm(quietZoneInches));
        bean.setBarHeight(height);

        boolean antiAlias = false;
        int orientation = 0;

        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                dpi, BufferedImage.TYPE_BYTE_BINARY, antiAlias, orientation);

        indiciaData = indiciaData.replaceAll("\\s+", "");
        byte[] binaryData = Base64.decodeBase64(indiciaData.getBytes());
        String base64DecodedMsg = StringUtils.newStringIso8859_1(binaryData);

        bean.generateBarcode(canvas, base64DecodedMsg);
        canvas.finish();


        String mime = MimeTypes.MIME_BMP;
        out = new ByteArrayOutputStream();

        final BitmapEncoder encoder = BitmapEncoderRegistry.getInstance(mime);
        encoder.encode(canvas.getBufferedImage(), out, mime, dpi);

I am using apache commons for conversion from base 64 我正在使用Apache Commons从Base 64进行转换

Jeremias pointed out the solution, just for the simplicity use: Jeremias指出了解决方案,只是为了简单起见:

new String("your string goes here written in UTF-8".getBytes("UTF-8"), "Cp437")

for example: 例如:

new String("ČĆŽŠĐ čćžšđ or Í".getBytes("UTF-8"), "Cp437")

you can check out barcode decoding online: http://online-barcode-reader.inliteresearch.com/default.aspx 您可以在线查看条形码解码: http//online-barcode-reader.inliteresearch.com/default.aspx

It works fine for Croatian diacritic characters, and it sohoud work for any UTF-8 character. 它适用于克罗地亚变音符号,也适用于任何UTF-8字符。 Srdačno. Srdačno。

You need to use new String(binaryData, "Cp437") instead of ISO-8859-1. 您需要使用新的String(binaryData,“ Cp437”)代替ISO-8859-1。 The page on PDF417 says to use that encoding. PDF417上页面说使用该编码。 Other encodings are not currently possible. 目前尚无法使用其他编码。 Unfortunately, the "Í" is not in Cp437 so can't be used. 不幸的是,“Í”不在Cp437中,因此无法使用。 If you download Barcode4J from CVS HEAD and compile it yourself, you can use RFC 2397 data URLs to use binary data: PDF417 description for development version . 如果从CVS HEAD下载Barcode4J并自己进行编译,则可以使用RFC 2397数据URL来使用二进制数据: 开发版本的PDF417描述

I tried changing Barcode4J PDF417HighLevelEncoder class and changed encoding to ISO-8859-1 in place of Cp437. 我尝试更改Barcode4J PDF417HighLevelEncoder类,并将编码更改为ISO-8859-1代替Cp437。 I generated a handful of barcodes and they are getting scanned correctly. 我生成了一些条形码,并且它们已被正确扫描。 Looks like it can be changed to support ISO 8859-1. 看起来可以更改为支持ISO 8859-1。

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

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