Unicode characters on ZPL printer

前端 未结 10 2148
既然无缘
既然无缘 2020-11-27 04:32

I have the task of re-designing a system to print shipping labels, using a networked Zebra GK420T. I have been able to send ZPL print jobs to it perfectly fine, but I cannot

10条回答
  •  天涯浪人
    2020-11-27 05:07

    You can replace character that greater then one byte to UTF-8 hex string with underscore like "ћ => _D1_9B". Sample code below;

     var zpl_code = "^XA" +
            "^LH100,150" +
            "^CWT,E:TT0003M_.FNT" +
            "^CFT,30,30" +
            "^CI28" +
            "^FT0,0^FDTesting 1 2 3^FS" +
            "^FT0,50^FDДо свидания^FS" +
            "^FT0,100^B3^FDAAA001^FS" +
            "^XZ";
            var unicodeCharacterList = zpl_code.Distinct()
                .Select(c => c.ToString())
                .Select(c => new { key = c, UTF8Bytes = Encoding.UTF8.GetBytes(c) })
                .Where(c => c.UTF8Bytes.Length > 1);
    
            foreach (var character in unicodeCharacterList)
            {
                var characterHexCode = string.Join("", character.UTF8Bytes.Select(c => "_" + BitConverter.ToString(new byte[] { c }).ToLower()).ToArray());
    
                zpl_code = zpl_code.Replace(character.key, characterHexCode);
            }
    

    This code set zpl_code variable to below output

    ^XA
    ^LH100,150
    ^CWT,E:TT0003M_.FNT
    ^CFT,30,30
    ^CI28
    ^FT0,0^FDTesting 1 2 3^FS
    ^FT0,50^FD_d0_94_d0_be _d1_81_d0_b2_d0_b8_d0_b4_d0_b0_d0_bd_d0_b8_d1_8f^FS
    ^FT0,100^B3^FDAAA001^FS
    ^XZ
    

提交回复
热议问题