javabarcodebarcode4j

Barcode4J pdf417 module is giving error


I am trying to convert binary data to pdf417 barcode using pdf417bean class of barcode4J. 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


Solution

  • I tried changing Barcode4J PDF417HighLevelEncoder class and changed encoding to ISO-8859-1 in place of Cp437. I generated a handful of barcodes and they are getting scanned correctly. Looks like it can be changed to support ISO 8859-1.