ZXing throws "Unable to fit message in columns" given valid data for PDF417 code

1k Views Asked by At

ZXing.dll -- zxing.net for .net 2.0 -- File version 0.14.0.1

My application does not allow auto-resizing (row/column calculation) of PDF417 codes. So, I use the selected settings to determine how many characters should be allowed, and then restrict user input.

ZXing is throwing "Unable to fit message in columns" exception in the call to PDF417Writer.encode, given parameters that should be valid, based on my calculations.

Example #1:

ErrorCorrection=Level3 (16 error codewords)
Compaction=Text (1.9 characters per codeword)
Rows=23, Columns=3 (69 codewords)
Calculated Capacity = 69 - 16 - 1 = 52 * 1.9 = 98.8 (98 characters)
Text = "0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ0123456789ABCDEFGH"
(98 text characters)

With those settings, ZXing can encode 94 characters but fails with 95 or more.

Example #2:

ErrorCorrection=Level0 (2 error codewords)
Compaction=Numeric (2.9 characters per codeword)
Rows=3, Columns=2 (6 codewords)
Calculated Capacity = 6 - 2 - 1 = 3 * 2.9 = 8.7 (8 characters)
Text = "123456" (6 numeric characters)

In this case, ZXing can encode up to 5 characters but fails with 6 or more.

Here is a small test program (C#) to reproduce the Example #2:

IDictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
hints.Add(EncodeHintType.MARGIN, 0);
hints.Add(EncodeHintType.ERROR_CORRECTION, PDF417ErrorCorrectionLevel.L0);
hints.Add(EncodeHintType.PDF417_COMPACT, false);
hints.Add(EncodeHintType.PDF417_COMPACTION, Compaction.NUMERIC);
hints.Add(EncodeHintType.PDF417_DIMENSIONS, new Dimensions(2, 2, 3, 3));
new PDF417Writer().encode("123456", BarcodeFormat.PDF_417, 0, 0, hints);

The following resource explains Example #1:

http://www.currentdirections.com/facts/sizing-applications-for-2d-symbols.html

Questions:

  1. Am I using ZXing in the right way to generate PDF417 code data?
  2. Am I calculating the capacity of PDF417 codes properly?
0

There are 0 best solutions below