I need to generate a PDF471 Barcode from a byte array and not from text.
How can this be done in Java?
There exists a solution in .NET:
Unfortunately this does not work in Java.
The basic way does not function:
String content = new String(data.readAllBytes(), StandardCharsets.UTF_8);
This ends up with additional bytes, which will cause an exception in the BarcodeGenerator like
“Maximum characters limit reached for BINARY compaction mode and 2 error correction level.
Encoded data length - 1345. Max available length - 1102.” - Where the initial byte array length is 782 - largely below the limit…
Doing something like:
byte dataBA = data.readAllBytes();
char charEncoded = new char[dataBA.length];
for (int i = 0; i < dataBA.length; ++i)
charEncoded[i] = (char)dataBA[i];
String content = new String(charEncoded);
doesn’t help either. The “problem” seems to be in the constructor of String.