Zebra Printer and character encoding

2019-09-19 08:02发布

I'm in a struggle with the encoding of characters with Zebra Printer.

I'm using ZebraDesigner and, for instance, I create a line with the text "Texte accentué". In the generated .prn file, the line is as follows : ^FT27,67^A0N,28,28^FH\^FDTexte accentu\82^FS

I'm guessing \82 is the encoded version of my letter é, but I don't find any relashionship between them two.

Any help would be welcome.

2条回答
Explosion°爆炸
2楼-- · 2019-09-19 08:19

^CI is the command that sets the encoding. That should be in your output as well. Look at the definition of that command in the ZPL guide to see how it

查看更多
倾城 Initia
3楼-- · 2019-09-19 08:35

Ok, I got through it : 0x82 (Hexa) or 130 (Dec) is the encoding for "é" in extended ASCII (Codepages 437 or 850 : http://www.ascii-codes.com/)

To convert my string, I have to use this PHP function :

$text = iconv('UTF-8', 'CP437//TRANSLIT', $text); // Also works with CP850

I finally made this little script, which converts only extended ASCII characters (Decimal code >= 128), as the basic ones are correctly understood, and I wanted my function to be run with the full file as an argument.

function zebraConvert($text)
{
    $return = '';
    $arr = str_split(iconv('UTF-8', 'CP437//TRANSLIT', $text));
    foreach ($arr as $char) {
        $ord = ord($char);
        if ($ord >= 128) {
            $return .= '\\' . dechex($ord);
        } else {
            $return .= $char;
        }
    }
    return $return;
}
查看更多
登录 后发表回答