ZPLPrinter Emulator SDK - Unicode UTF8 Text Support
Product ZPLPrinter Emulator SDK for .NET STANDARD Published 11/18/2019 Updated 01/30/2021 Author Neodynamic
Overview
Some ZPL commands could contain Unicode / UTF-8 text in different languages. ZPLPrinter Emulator SDK for .NET STANDARD can preview, render and convert those commands to any image format or document format but some considerations must be taken into account depending on the language to be processed.
- If the ZPL commands contain a reference to TT0003M_.FNT or TT0003M_.TTF fonts, then ZPLPrinter Emulator SDK for .NET STANDARD will render the text without any issues. That font supports Latin, Greek, Cyrillic, Eastern European, Turkish, Arabic, and Hebrew characters.
LIMITATION! If the ZPL commands contains texts in RTL (Right-to-Left) languages like Arabic and Hebrew then it cannot be mixed with non-RTL text inside the same ^FD command. - If the ZPL commands contain a reference to SIMSUN.FNT font, then it's likely that the text is in Chinese (Simplified) language. To allow ZPLPrinter Emulator SDK for .NET STANDARD to render the text, that font must be added to the virtual ZPL printer storage.
- If the ZPL commands contain a reference to ANMDS.TTF, ANMDT.TTF, ANMDJ.TTF, or ANMDK.TTF fonts, then it's likely that the text is in Chinese (Simplified - Traditional), Japanese, or Korean languages. Those fonts are from Andale Mono WT family. To allow ZPLPrinter Emulator SDK for .NET STANDARD to render the text, the involved fonts must be added to the virtual ZPL printer.
- If the ZPL commands contain a reference to any Custom Font (*.ttf), then to allow ZPLPrinter Emulator SDK for .NET STANDARD to render the text, that font must be added to the virtual ZPL printer storage.
Sample code for using a Custom TTF Font supporting Unicode CharSet
The following sample code will add to the Virtual ZPLPrinter Storage the Arial Unicode TTF font for rendering texts in different languages. The same apporach can be used to render texts when using the aforementioned Asian fonts.
Please follow up these steps
- Be sure you download the Arial Unicode font (in our case, that font is located here
c:\Windows\Fonts\ARIALUNI.TTF
). Remember that any added font remain the exclusive property of their specific owners and require a license from their owners. - Open Visual Studio 2017+ and create a new Console App project
- Add a reference to the ZPLPrinter Emulator SDK for .NET STANDARD 2.0+ package from NuGet
- The sample code will add the Arial Unicode font (c:\Windows\Fonts\ARIALUNI.TTF) to the ZPLPrinter internal storage as R:ARIUNI.FNT so it can then be referenced in the ZPL commands to render texts in different languages. The following are a sample of ZPL commands referencing to Arial Unicode R:ARIUNI.FNT that will be processed by our ZPLPrinter Emulator
The output of the ZPL commands processing will be in PDF format. Please copy/paste the following code inside the Main method of the Console App.^XA ^CWZ,R:ARIUNI.FNT^FS ^FO10,50^CI28^AZN,50,50^FDUNICODE using CI28 UTF-8 encoding^FS ^FO010,160^CI28^AZN,50,40^FDRoman: ABCDEFGHIJKLMNOPQRSTUVWXYZ^FS ^FO010,230^CI28^AZN,50,40^FDCyrillic: ЁЂЃЄЅІЇЈЉЊЋЌЎЏАБВГДЕЖЗИЙКЛМН^FS ^FO010,300^CI28^AZN,50,40^FDEastern: ŠŚŤŽŹŁĄŞŻĽľŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎ^FS ^FO010,370^CI28^AZN,50,40^FDGreek: ΆΈΉΊΌΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫ^FS ^FO010,440^CI28^AZN,50,40^FDTurkish: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎĞÑÒÓÔÕÖ×ØÙÚÛÜİŞ^FS ^PA1,1,1,1^FS ^FO010,510^CI28^AZN,50,40^FDزيبرة تكنوليجيز اوربا المحدودة^FS ^FO010,580^CI28^AZN,50,40^FDChinese: 中文字符^FS ^PQ1 ^XZ
NOTE: Please change the code below to be sure that the Arial Unicode ttf file path is reached.C#
//Create an instance of ZPLPrinter class ZPLPrinter zplPrinter = new ZPLPrinter("License Owner", "License Key"); //Set printer DPI //The DPI value to be set must match the value for which //the ZPL commands to be processed were created!!! zplPrinter.Dpi = 203; //set label size e.g. 4in x 6in zplPrinter.LabelWidth = 4.0 * zplPrinter.Dpi; zplPrinter.LabelHeight = 6.0 * zplPrinter.Dpi; //Apply antialiasing zplPrinter.AntiAlias = true; //Set image or doc format for output rendering zplPrinter.RenderOutputFormat = RenderOutputFormat.PDF; //ADD Unicode FONT e.g. Arial Unicode zplPrinter.AddFont("R:ARIUNI.FNT", @"c:\Windows\Fonts\ARIALUNI.TTF"); //ZPL commands sample string zplCommands = ""; zplCommands += "^XA"; zplCommands += "^CWZ,R:ARIUNI.FNT^FS"; zplCommands += "^FO10,50^CI28^AZN,50,50^FDUNICODE using CI28 UTF-8 encoding^FS"; zplCommands += "^FO010,160^CI28^AZN,50,40^FDRoman: ABCDEFGHIJKLMNOPQRSTUVWXYZ^FS"; zplCommands += "^FO010,230^CI28^AZN,50,40^FDCyrillic: ЁЂЃЄЅІЇЈЉЊЋЌЎЏАБВГДЕЖЗИЙКЛМН^FS"; zplCommands += "^FO010,300^CI28^AZN,50,40^FDEastern: ŠŚŤŽŹŁĄŞŻĽľŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎ^FS"; zplCommands += "^FO010,370^CI28^AZN,50,40^FDGreek: ΆΈΉΊΌΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫ^FS"; zplCommands += "^FO010,440^CI28^AZN,50,40^FDTurkish: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎĞÑÒÓÔÕÖ×ØÙÚÛÜİŞ^FS"; zplCommands += "^PA1,1,1,1^FS^FO010,510^CI28^AZN,50,40^FDزيبرة تكنوليجيز اوربا المحدودة^FS"; zplCommands += "^FO010,580^CI28^AZN,50,40^FDChinese: 中文字符^FS"; zplCommands += "^PQ1"; zplCommands += "^XZ"; try { //Let ZPLPrinter to process the specified ZPL commands //and display rendering output if any... List<byte[]> outBuffer = zplPrinter.ProcessCommands(zplCommands, Encoding.UTF8); // the buffer param contains the binary output of the ZPL rendering result // The format of this buffer depends on the RenderOutputFormat property setting if (buffer != null && buffer.Count > 0) { if (zplPrinter.RenderOutputFormat == RenderOutputFormat.PDF) { System.IO.File.WriteAllBytes("c:\temp\outputLabel.pdf", buffer[0]); } } } catch (Exception ex) { throw ex; }