Print characters with an acute in ZPL - utf-8

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.

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

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.

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)

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:
Downloading and using fonts on zebra zpl printers
ZPL Online editor
A mix from the answers for this question

Related

Vietnamese text printing on ZPL printer using Zpl commands

I am trying to print Vietnamese text on my Zebra label using Zpl coding.
But i am getting issues in vietnamese characters. For example, i am trying to print a label with text "Nhập khẩu" but it is giving me the output "Nh p kh u", thus missing the Vietnamese fonts.
I have tried using Andale and Swiss font and also declaring the ^CI28 tag for printing various characters in utf-8 encoding.
If anyone else has any other inputs, please let me know.. thanks in advance..
EDIT:
This is the code i am using..
^XA^CWZ,E:TT0003M_.TTF^FS^XZ
^XA
^CF01,20,15
^CI28
^FO20,20^FDNhập khẩu - LOẠI:For Fujifilm^FS
^XZ
Have you tried google's Noto fonts?
https://fonts.google.com/specimen/Noto+Sans
I have used them to render Vietnamese. If that doesn't work, post the sample ZPL you have tried and we can work through it.
Here is some example ZPL. This assumes the Noto Sans font is saved to the printer as E:NOTOSANS.TTF:
^XA^CI28
^A#N,32,32,E:NOTOSANS.TTF
^FO50,50
^FDNhập khẩu^FS
^XZ

zebra printer not printing latin characters

I have a problem with zebra printer ZT410, i'm trying to print in latin characters such as ñ, ç and ò and so on.
^XA
^CI28
^MMT
^PW1040
^LL840
^A#N,50,49,E:STI000.FNT^FT50,-230^FH\^FDRajoy^FS
^A#N,50,49,E:STI000.FNT^FB1040,2,25,C^FT0,-421^FH\^FDThañk yòú fôr showing me that there are people^FS
^A#N,50,49,E:STI000.FNT^FB1040,1,0,C^FT0,-509^FH\^FDlike you in this world.^FS
^A#N,50,49,E:STI000.FNT^FB1040,1,0,C^FT0,-572^FH\^FD^FS
^A#N,50,49,E:STI000.FNT^FB1040,1,0,C^FT0,-635^FH\^FDLoveç you.^FS
^A#N,50,49,E:STI000.FNT^FB1040,1,0,C^FT0,-698^FH\^FDMarta.^FS
^A#N,50,49,E:STI000.FNT^FT50,-790^FH\^FDDavid^FS
^XZ
But instead of printing the special characters, they are omited, I've checked that the special font used (Stingray) contains all those characters, I don't know how to print them. Any help would be appreciated. Thanks
Edit: I actually fixed it by using ^CI27 instead of ^CI28 since I have an older version of the Zebra firmware that doesn't support ^CI28
Here's something simple that works with some of the text you have:
^XA
^CI28
^FO50,20^A0N,40,40^FDThañk yòú fôr showing me that there are people^FS
^XZ

ZPL fieldblock ^FB for unicode fonts

I am using ZQ520, its already supports Unicode and I am loading the font as follows:
^XA ^CWZ,E:TT0003M_.FNT^FS^XZ
I can use the font to print Arabic as follows:
^FO100,50^CI28^AZN,0,25^FD ARABIC TEXT HERE ^FS
It works fine but when I use ^FB with ^FO, the Arabic letters get messed up and gets separated (In Arabic, they are connected), here an example:
^FO100,50^FB200,,,R,^CI28^AZN,0,25^FD ARABIC TEXT HERE^FS
so it seems that ^FB does not support the Unicode font. on page 187 of the manual its mention this
The ^FB command does not support complex text. For complex text
support, use ^TB.
And 179
The Field Block (^FB) command cannot support the large TrueType fonts.
Is there a way around this? Because Arabic is right to left, so I am trying to make the text right aligned and multi-line as some strings are long.
I managed to print out word wrapping Arabic text using ^TB using the following code. It may be useful to adapt for your own purposes.
^XA^LRN^CI28^CWZ,E:TT0003M_.FNT^FS
^FO600,10,2
^AZN,50,40
^TBN,600,100
^FH
^FD
arabic text here
^FS
^PQ1
^XZ
Useful links:
TB command (some extra info compared to below link): https://support.zebra.com/cpws/docs/zpl/TB_Command.pdf
Please note that it states the ^TB command must be issued after any ^Ax (font selection) command
ZPL Manual: https://www.zebra.com/content/dam/zebra/manuals/en-us/software/zpl-zbi2-pm-en.pdf

QTextDocument print to pdf and unicode

I try to print pdf file from QTextDocument. Content of document is set by setHtml().
Simplified example:
QTextDocument document;
document.setHtml("<h1>My html \304\205</h1>"); // Octal encoded ą
QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("cert.pdf");
document.print(&printer);
It does not work as expected on windows (msvc). I get pdf file with "?" in place of most polish characters. It works on ubuntu.
On windows It makes pdf with tahoma font embedded subset. How to force QPrinter or QPrintEngine to embed more characters from this (or any other) font?
As pepe suggested in comments. I needed to wrap this string one of:
QString::fromUtf8
tr() (in case of joining translated parts)
Use html escape sequence (ex. &#261 for ę)
My original html in program was build from tr() parts, but I forgot to octal escape some of them. (which worked on gcc, not on msvc, even with utf-8 with BOM)

How to print French characters with an acute (like 'é') with a Zebra P4t printer

My question is about printing French characters with an acute like: é è à ô etc. with a Zebra P4t printer.
Consider the ZPL instructions below:
^XA
^FO20,20
^CI28
^A0,20,20
^FD
Amitié
^FS
^XZ
I have put these instructions into a file encoded as UTF-8.
When I send this file to a Zebra GK420t printer, I get the expected result concerning the character with an acute é at the end of the French word Amitié that you can see above. It is printed properly.
Now, when I send this very same file to a Zebra P4t printer it prints something like |-® instead of the é character.
The firmware of the printer is SHCPT11z48.
Alos, if you consider the ZPL instructions below:
^XA
^FO20,60
^A0,20,20
^FD
Amitié
^FS
^XZ
I have put these instructions into a file encoded as ANSI.
Now, when I send this very same file to a Zebra P4t printer it prints Ú instead of the é character.
I really don't see where this character Ú is coming from.
What can I do to solve that problem?
Is a font missing in the printer?
Am I not sending compatible ZPL instructions?
Thank you and best regards.
You have to prefix the field with UTF-8 characters with ^FH (Field Hexadecimal Indicator) and replace every UTF-8 character with their unicode hexadecimal code prefixed by an _ (list, example for é):
^XA
^FO20,20
^CI28
^A0,20,20
^FD
Amiti_C3_A9
^FS
^XZ
Simple solution without having to replace anything:
After the opening tag ^XA add ^CI28.
^XA^CI28
your content
^XZ
Zebra support talking about it here.

Resources