I'm trying to encoding more than 2000 characters in a barcode.
Random random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var text = new string(Enumerable.Repeat(chars, 2000)
.Select(s => s[random.Next(s.Length)]).ToArray());
var barcode = new BarcodePDF417();
barcode.SetText(text);
barcode.GetImage();
When trying to GetImage(), I recieve an Error.
System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values. (Parameter 'The text is too big.')'
I understand that there is a Macro version where you can link data. However, the resulting barcode is no longer uniform. I want just 1 scannable barcode. Is this achievable using ITextSharp?
barcode.MacroFileId = "0"
barcode.MacroSegmentId = someIndexinLoop;
barcode.MacroSegmentCount = totalCount;
No, it is not possible within a single PDF417 complaint barcode.
You could use multiple barcodes or a link to more data as suggested, or if you have control over the application that will be reading the barcode then you can employ fancy tricks like short-codes within the barcode that can be expanded to some pre-set string by the application doing the scanning.
The PDF417 specification as shown in the ISO spec, or here does have limits:
PDF417 is capable of encoding more than 1100 bytes, 1800 text characters or 2710 digits. Large data files can be encoded into a series of linked PDF417 symbols using a standard methodology referred to as Macro PDF417.
And there is some great information here:
It is recommended to limit the amount of data in each 2D barcode symbol to 800 characters or less, using 20 columns or less. Although the specification states that “up to 1100 bytes or 1800 ASCII characters can be encoded in a PDF417 symbol,” it is not usually achievable. The amount of data that can be encoded will vary depending upon the type of data, the compaction type, the error correction level chosen and the limitation of the scanner being used. For example, in text compaction mode, the amount of compaction varies due to mode switching between different types of characters, such as between numbers, upper case, lower case and punctuation. In addition, many PDF417 CCD scanners do not reliably read more than 800 to 850 characters and some scanners have limits of only 300 characters.