11
votes

If I send the ZPL commands below to a Zebra printer, it prints AmitiÙ:

^XA
^FO50,20
^CI7
^A0N,25,15
^FD
Amitié
^FS
^XZ
  • Note that the file encoding is ANSI.
  • Note the use of the ZPL command ^CI7 (7 => Single Byte Encoding - France 1 Character Set).

On the other hand, if I send the ZPL commands below to a Zebra printer, it prints Amitié (which is what I actually need to get):

^XA
^FO50,20
^CI28
^A0N,25,15
^FD
Amitié
^FS
^XZ
  • Note that the file encoding is UTF-8.
  • Note the use of the ZPL command ^CI28 (28 => Unicode (UTF-8 encoding) - Unicode Character Set).

Do you know what's wrong in the first case?

Thank you for helping.

4

4 Answers

19
votes

Use UTF-8 by placing a ^CI28 command at the top of your ZPL template, eg

^XA
^CI28
^CF0,80
^FO70,40^FDavión^FS
^XZ
3
votes

According to the programing guide document from Zebra ^CI using 7 will get you Code Page 850 with some specific character replacements. When you say you had the file encoded in ANSI, I assume you mean Code Page Windows-1252 or ISO-8859-1 (latin1).

The character é in Windows-1252 and latin1 is #00E9, but that's Ú in 850; you would want #0082 for é in 850. Using ^CI7 you could apparently also get an é with #007B since that's one of the specific character replacements made with that command.

Using UTF8 (with ^CI28) is probably the way to go since it's widely supported and understood, but note that you could also try ^CI27 (which may work even if you have an older version of the Zebra firmware that doesn't support ^CI28) and that should get you code page 1252. If that doesn't work you'll need to encode your text using code page 850.

1
votes

If you copy and paste your first example into a text editor that can convert between UTF-8 and ANSI (Notepad++) you'll see that the first example is encoded as

^XA
^FO50,20
^CI7
^A0N,25,15
^FD
Amitié
^FS
^XZ

And this will be cause problems with your ZPL when rendered. See online examples for ANSI and UTF-8.

To fix this you could encode your values first (for example as hex and then prefix with ^FH)

0
votes

Here is what I did to be able to do that:

  • Define UTF-8 charset using ^CI28
  • Use Swiss unicode font. For my case I only needed to encode on a single line and I didn't want to change anything else on the document or printer settings. For that I used ^A@N,44,30,E:TT0003M_.TTF. If you want to define the font for the whole document check the first link below.
  • Prepared the string to recognize UTF-8 encoding with ^FH immediately before ^FD
  • Encoded the document to replace non-ASCII characters with their HEX representation:
    private static string ZebraEncode(string text)
    {
        var ret = new StringBuilder();

        var unicodeCharacterList = new Dictionary<char, string>();
        foreach(var ch in text)
        {
            if (!unicodeCharacterList.ContainsKey(ch))
            {
                var bytes = Encoding.UTF8.GetBytes(ch.ToString());
                if (bytes.Length > 1)
                {
                    var hexCode = string.Empty;
                    foreach(var b in bytes)
                    {
                        hexCode += $"_{BitConverter.ToString(new byte[] { b }).ToLower()}";
                    }

                    unicodeCharacterList[ch] = hexCode;
                }
                else
                    unicodeCharacterList[ch] = ch.ToString();

                ret.Append(unicodeCharacterList[ch]);
            }
            else
                ret.Append(unicodeCharacterList[ch]);
        };

        return ret.ToString();
    }

Info that I gathered in order to reach a solution: