使用PHP打印到热敏收据打印机

cu6pst1q  于 2023-02-11  发布在  PHP
关注(0)|答案(1)|浏览(158)

我有下面的代码,应该使它能够打印一些东西到热敏收据打印机。

if ($_GET['action'] == 'print')
{
    $printer = "\\\\localhost\\zebra";

    // Open connection to the thermal printer
    $fp = fopen($printer, "w");
    if (!$fp){
      die('no connection');
    }

    $data = " PRINT THIS ";

    // Cut Paper
    $data .= "\x00\x1Bi\x00";

    if (!fwrite($fp,$data)){
      die('writing failed');
    }

}

虽然,当我运行它时,没有任何事情发生沿着没有任何错误。如何从PHP打印?

x4shl7ld

x4shl7ld1#

试试这个...

<?php 
if ($_GET['action'] == 'print')
{
$printer = "\\\\localhost\\zebra"; 
if($ph = printer_open($printer)) 
{ 
   $data = " PRINT THIS ";  
   // Cut Paper
   $data .= "\x00\x1Bi\x00";
   printer_write($ph, $data); 
   printer_close($ph); 
} 
else die('writing failed');
}
?>

相关问题