如何在PHP中使用.prn文件打印Data Matrix中的回车符和换行符

gt0wga4j  于 2023-11-16  发布在  PHP
关注(0)|答案(2)|浏览(153)

我需要打印一个DataMatrix与载体返回和换行。我的打印机是一个斑马GK 420 t。我在斑马设计师的标签,当标签打印从斑马设计师的CR和LF工作,但当我导出标签到PRN文件,打印与PHP,CR和LF不工作。
PHP代码

<?php
class ZebraBarcode {
    var $host = "";
    var $port = "";
    var $error = "";
    var $prn = "";

    function __construct($host,$port) {
        $this->host = $host;
        $this->port = $port;

        $this->prn = "CT~~CD,~CC^~CT~
^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR2,2~SD30^JUS^LRN^CI0^XZ
^XA
^MMT
^PW799
^LL0400
^LS0
^FO4,4^GB795,396,8^FS
^FO5,197^GB794,101,8^FS
^FT642,236^A0N,25,26^FH\^FDCANTIDAD^FS
^FT275,67^A0N,37,52^FH\^FDMEMORIA GRABADA^FS
^FT587,328^A0N,28,28^FH\^FDLOTE^FS
^FT355,328^A0N,28,28^FH\^FDPANEL^FS
^FT22,329^A0N,28,28^FH\^FDMODELO^FS
^FT30,236^A0N,25,26^FH\^FDSEMIELABORADO^FS
^FT34,122^A0B,25,24^FH\^FDEBS^FS
^FT34,277^A0N,34,33^FH\^FD4-651-IAPOWTV00148^FS
^FT587,381^A0N,39,38^FH\^FDL104^FS
^FT355,380^A0N,39,38^FH\^FDHIR^FS
^FT21,381^A0N,39,38^FH\^FD32LD846HT^FS
^FT294,165^A0N,90,88^FH\^FDOP-84366^FS
^FT613,283^A0N,42,69^FH\^FD99000^FS
^BY160,160^FT53,187^BXN,5,200,0,0,1,_
^FH\^FDOP-84188\0D\0A4-651-IAPOWTV00148\0D\0APLA\0D\0A99000\0D\0A100\0D\0AP3-UshZebra3^FS
^FO15,333^GB773,0,6^FS
^FO575,299^GB0,92,4^FS
^FO344,299^GB0,92,4^FS
^LRY^FO593,208^GB0,79,7^FS^LRN
^LRY^FO582,300^GB206,0,31^FS^LRN
^LRY^FO351,300^GB222,0,32^FS^LRN
^LRY^FO602,208^GB185,0,34^FS^LRN
^LRY^FO16,300^GB325,0,32^FS^LRN
^LRY^FO264,26^GB470,0,54^FS^LRN
^LRY^FO17,208^GB222,0,34^FS^LRN
^LRY^FO14,14^GB0,180,23^FS^LRN
^PQ1,0,1,Y^XZ
";
    }

    function Imprimir(){
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket === false) {
            $this->error = "socket_create() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
            return false;
        }

        $result = socket_connect($socket, $this->host, $this->port);
        if ($result === false) {
            $this->error = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
            return false;
        }

        socket_write($socket, $this->prn, strlen($this->prn));
        socket_close($socket);
        return true;
    }       
}

$o = new ZebraBarcode("10.30.30.128",9100); 
$o->Imprimir();
?>

字符串
代码工作!!,但CR和LF仍然不工作.任何想法?
提前感谢!

b1uwtaje

b1uwtaje1#

十六进制值通常用_(下划线)转义。
尝试_0D_0A而不是\0D\0A

afdcj2ne

afdcj2ne2#

要在数据矩阵中打印换行符,必须将“\0D\0A”更改为“_0D_0A”
随附官方文档:https://supportcommunity.zebra.com/s/article/Including-Carriage-Return-Line-Feed-in-QR-Barcode-Using-ZPL?language=en_US

相关问题