如何使用PHP中的tsc ttp-244 pro打印机打印条形码

时间:2017-02-13 06:11:58

标签: php

我正在做条形码打印标签应用程序。我正在使用tsc ttp-244专业打印机。如何编写条形码标签的php代码以将打印件发送到打印机?

请帮助解决此问题。

请检查以下代码     打开打印机

<?php

$handle = printer_open('TSC TTP-244 Pro'); //or it could be  


//set printing option to raw
printer_set_option($handle, PRINTER_MODE, 'RAW');
 printer_set_option($handle, PRINTER_COPIES, '1');

 //write data to printer
$esc = chr(27);
$data = '';
$data .= $esc . 'A';
$data .= $esc . 'A3H1374V0001';
$data .= $esc . 'H0050' . $esc . 'V0100' . $esc . 'L0303' . $esc . 'XMSATO';
$data .= $esc . 'H0050' . $esc . 'V0200' . $esc . 'B103100*SATO*';
$data .= $esc . 'H0170' . $esc . 'V0310' . $esc . 'L0101' . $esc . 'XUSATO';
$data .= $esc . 'Q1';
$data .= $esc . 'Z';


$ret = printer_write($handle, $data);
//close the printer handle
printer_close($handle);

?>

1 个答案:

答案 0 :(得分:0)

查看https://github.com/leesaw/pradit/blob/b91513e3978e75610a0bbd06cfa4751fb3702f16/tsc/printbarcode.php

上的示例

您应该学习此代码https://github.com/leesaw/pradit/tree/b91513e3978e75610a0bbd06cfa4751fb3702f16

          $TSCObj  = new COM ("TSCActiveX.TSCLIB") or die("Unable to open COM object");
          $TSCObj->ActiveXopenport("TSC TTP-244 Plus");           
          //$TSCObj->ActiveXdownloadpcx("C:/xampp/htdocs/pradit/tsc/logo.pcx","logo.pcx");
          $TSCObj->ActiveXsetup("104", "52", "3", "10", "0", "2", "0");
          //$TSCObj->ActiveXformfeed();
          //$TSCObj->ActiveXsendcommand("HOME");
          //$TSCObj->ActiveXsendcommand("SET TEAR OFF");
          $TSCObj->ActiveXclearbuffer();
          //$TSCObj->ActiveXsendcommand("PUTPCX 300,250,\"logo.pcx\"");

          // print product name
          $name1 = iconv("UTF-8", "TIS-620", $_GET['name']);
          $TSCObj->ActiveXwindowsfont(60, 50, 54, 0, 2, 0, "Angsana New", $name1);
          $TSCObj->ActiveXwindowsfont(450, 50, 54, 0, 2, 0, "Angsana New", $name1);

          // print product price + vat
          $price1 = "ÃÒ¤Ò ".number_format($_GET['price'], 2, '.', ',')." ºÒ·";
          $TSCObj->ActiveXwindowsfont(60, 330, 54, 0, 2, 0, "Angsana New", $price1);
          $TSCObj->ActiveXwindowsfont(450, 330, 54, 0, 2, 0, "Angsana New", $price1);

          // print barcode
          $TSCObj->ActiveXbarcode("60", "110", "128", "200", "1", "0", "2", "2", $_GET['bc']);  
          $TSCObj->ActiveXbarcode("450", "110", "128", "200", "1", "0", "2", "2", $_GET['bc']); 

          // print number of copies
          $copy = ceil($_GET["copy"]/2);
          if ($copy > 0) {
            for ($i=0; $i<$copy; $i++) {
                $TSCObj->ActiveXprintlabel("1","1");
            }
            echo "Printing....";
          }else{
            echo "Error!!!";
          }
          //$TSCObj->ActiveXformfeed();
          $TSCObj->ActiveXcloseport();