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

时间:2014-02-07 04:24:12

标签: php printing

我有以下代码可以让它能够将内容打印到热敏收据打印机上。

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打印?

1 个答案:

答案 0 :(得分:0)

试试这个......

<?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');
}
?>