#11 java.lang.IllegalArgumentException


I’m trying to implement a 10 digit number, image, and 2 check digits using the PDF417 barcode routine. I’m currently receiving a non-encodeable character when trying to implement this which occurs when processing the image. As I understand the problem, this happens in the PDF417HighLevelEncoder.getBytesForMessage routine when it tries to convert the msg string to byte[] using the cp437 code page. I believe this character(Unicode 216) is not found in the CP437 code page and a ascii 63 is passed back resulting in the following error. I’m not sure how to pass back the image to avoid this error or the way I am implementing this is correct or incorrect? I tried mapping the data image using the cp437 table which avoids this error, but then receives a java.lang.ArrayIndexOutOfBoundsException: 1556 array out of bounds error. Can you tell me if the image I am sending to the PDF417 barcode routine is correct or what format is this routine looking for when processing an image.

Your help is most appreciated!

Thanks in advance

The error that I am getting is as follows:

java.lang.IllegalArgumentException: Non-encodable character detected: ? (Unicode: 216)
at sa.gov.nic.passport.reports.PDF417HighLevelEncoder.determineConsecutiveBinaryCount(PDF417HighLevelEncoder.java:529)
at sa.gov.nic.passport.reports.PDF417HighLevelEncoder.encodeHighLevel(PDF417HighLevelEncoder.java:143)
at sa.gov.nic.passport.reports.PDF417LogicImpl.generateBarcodeLogic(PDF417LogicImpl.java:187)
at sa.gov.nic.passport.reports.PDF417Bean.generateBarcode(PDF417Bean.java:71)
at sa.gov.nic.passport.reports.BarCodeFactory.barCodePDF417(BarCodeFactory.java:250)
at sa.gov.nic.test.servlets.PSRP0005App.main(PSRP0005App.java:209)

Code I am using:

PDF417Bean bean = null;
BufferedImage barCodeImage = null;

try {

//Create the barcode bean
bean = new PDF417Bean();

final int dpi = 150;

BitmapCanvasProvider canvas = new BitmapCanvasProvider(dpi, BufferedImage.TYPE_BYTE_BINARY, true, 0);
File file = new File("D:\\Java Tools\\PS-Reports\\bwSamisPhoto.jpg");

InputStream inFile = new FileInputStream(file);
byte[] byteImage = new byte[(int)file.length()];

StringBuffer buf = new StringBuffer();

// Append number to Buffer

// Append image to buffer
for (int i=0; i < byteImage.length; i++) {
buf.append( (char) (byteImage[i] &0x0ff ) );

// Create 2 Check Digits
char[] checkDigits = createCheckDigits(barCodeMsg);

//Generate barcode
bean.generateBarcode(canvas, buf.toString());

// Move to barcode to image
barCodeImage = canvas.getBufferedImage();

//Signal end of generation

System.out.println("Barcode Generated");

} catch (Exception e) {


  • Logged In: YES
    Originator: NO

    I'm sorry I don't have enough time to dive in deeper at the moment, so just a few comments:
    - The way you encode the image will definitely not work as the you're using "UTF-8" encoding like this instead of "cp470". Use this instead:
    buf.append(new String(byteImage, "cp470")) but no guarantee that this will work. If not all 256 characters of cp470 are mapped to unique value in Unicode, it's not going to work (and I haven't checked). I hope to add support for binary data at some point but lately there's simply too much going on.
    - If you have exceptions like the ArrayIndexOutOfBoundsException please try working with the current HEAD version from CVS. I've fixed a number of bugs since the last release. Maybe this is fixed, too.

    Good luck! I'm keeping the issue open so I don't forget to look into it when I've got time.