I get my DataMatrix code using the following line:
BitMatrix bitMatrix = new DataMatrixWriter().encode(dmie.preEncodeBarcode(dataToEncode), BarcodeFormat.DATA_MATRIX, 50, 50, null);
The input string I get contains "FNC1" (just as plain characters in the string) to mark the end of a dynamic field, and in total the string has 4 different GS1 DataMatrix Application Identifiers and their respective values.
What preEncodeBarcode() does is to replace "FNC1" with <GS>
, like so:
input = input.replaceAll("FNC1", new String(new byte[] {0x1d}));
Since otherwise I simply get "FNC1910005FNC1230202[...]" encoded in the DataMatrix, while what I want is of course <GS>
instead of the text "FNC1".
However, when replacing FNC1 with <GS>
(I've tried using '\u001c' as well), I get this very strange double-DM-code instead of a normal one:
Only if I skip replacing "FNC1" with <GS>
do I get a proper one.
Any idea how to get a proper DataMatrix code based on my <GS>
-containing String? Or am I simply doing something wrong by having <GS>
directly in the String? What should I do instead in that case to get zxing to give me a correct DataMatrix? I've been reading all over but I really can't wrap my head around this.
Update: I'm not sure, but I might be on to some strange sort of bug here. This is what I'm sending to the DataMatrixWriter once I've preprocessed the input string (spaces are ):
[d29100001 21000000049347037 24000163718 390300000002990
What I find rather obscure is that if I (at the time of writing) send input.substring(2, input.length());
or input.substring(0, input.length()-3);
then it works just fine, while if I instead remove only one (or less) character from the beginning or 2 or less from the end then I get this strange DataMatrix. What's even stranger is that this behaviour is not even consistent - if I add say 6 some random numbers at the end then it works fine, but if I then remove three of those numbers then I again I get the problem. And worst of all, an hour ago I couldn't send in input.substring(0, input.length()-3)
, but now I can.
In other words, I'm utterly perplexed.
(PS. I am using the code found here to scale the DataMatrix to the size I want, but it's zxing that gives the wrong output from the start.)