This project has moved and is read-only. For the latest updates, please go here.

PDF417 decoding problem

Apr 23, 2014 at 2:06 PM
Hi, i was very helped because of this project for my final project, but I still have a problem because I have encoded the PDF417 barcode from array of byte which are encoded with 437 page. How should I do to get those array of byte back? because if I use result.text , there so many character that I miss from the decoded result.

Apr 23, 2014 at 8:07 PM
Please provide an image of your PDF417 barcode and the original data which is encoded in the barcode.
Apr 24, 2014 at 1:35 AM
this is the image , the byte of array which are encoded have value from 0x00-0xFE (256 char with null at the end)

0x00-0x01-0x02-0x03- .............0xFD-0xFE-0x00
Apr 28, 2014 at 9:20 PM
CP437 doesn't work very well with characters above the byte value 127.
I wrote a little test method which shows a way to encode and decode a byte array as PDF417.
That's the only way I found which works.

Your sample image gives a correct result if you convert the resulting string back to a byte array with the following line:
// result is a instance which is given by the Decode method
var resultBytes = Encoding.GetEncoding("iso8859-1").GetBytes(result.Text);
CP437 doesn't work here because it gives not the correct values for bytes which are greater than 127.

The test method for a complete encoding-decoding roundtrip
      public void PDF417_Byte_Array_With_ISO8859_1_RoundTrip_Byte_Compaction_Without_ECI()
         // prepare the raw byte content
         var rawByteContent = new byte[256];
         for (var index = 0; index < 254; index++)
            rawByteContent[index] = (byte)index;
         // encode the raw bytes as a string with ISO8859-1 text encoding
         var content = System.Text.Encoding.GetEncoding("ISO8859-1").GetString(rawByteContent);

         // encode the string content as PDF417, give a hint to the barcode writer about the text encoding
         var barcodeWriter = new BarcodeWriter
               Format = BarcodeFormat.PDF_417,
               Options = new PDF417EncodingOptions
                     CharacterSet = "ISO8859-1",
                     Compaction = Compaction.BYTE,
                     DisableECI = true
         var barcodeBitmap = barcodeWriter.Write(content);

         // scan the bitmap
         var barcodeReader = new BarcodeReader();
         var scannedResult = barcodeReader.Decode(barcodeBitmap);

         // convert the string result back to a byte array
         var scannedResultRawBytes = System.Text.Encoding.GetEncoding("ISO8859-1").GetBytes(scannedResult.Text);

         // compare the content
         for (var index = 0; index < scannedResult.Text.Length; index++)
            Assert.That(scannedResultRawBytes[index], Is.EqualTo(rawByteContent[index]));
Apr 29, 2014 at 9:34 AM
Whooohaaa, Thanks for your response mic, This is help me a lot.
I just found out this latest version of zxing and its have a lot of improvement than I downloaded before.
Wish You blessed for your kindness :)