Print characters with an acute in ZPL
Asked Answered
B

4

14

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.

Blowfly answered 3/4, 2015 at 17:55 Comment(0)
E
26

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
Epicenter answered 7/6, 2017 at 16:49 Comment(0)
L
5

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.

Ladybird answered 13/12, 2017 at 3:31 Comment(0)
E
1

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)

Epicycloid answered 17/3, 2017 at 12:9 Comment(0)
L
1

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:

Limiter answered 6/6, 2019 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.