dongmei1828 2015-06-05 12:49
浏览 598
已采纳

如何使用PHP将ZPL字体或图像发送到Zebra打印机

I know how to printer ZPL via PHP using fsockopen but I also have a few ZPL files containing the fonts and graphics used on my labels.

Can anyone tell me how to send a raw ZPL file to a printer using PHP? For now I'm using Zebranet Bridge but I prefer to be able to accomplish this from PHP.

  • 写回答

1条回答 默认 最新

  • dsjgk330337 2015-06-15 19:59
    关注

    Assuming you know how to send ZPL commands to the printer via PHP, and you want to print a font or graphic by the same means, you have to

    1. get the size of your resource and convert its binary data to an ASCII hexadecimal string:

      <?php
      $res_size = 0;
      $res_string = "";
      $res_source = "http://php.net/images/logo.php";
      $handle = fopen($res_source,"rb");
      while (!feof($handle)) {
          $data = fread($handle,1);
          $res_size++;
          $res_string .= bin2hex($data);
      }
      ?>
      
    2. compose a ZPL script to download the converted resource to printer memory:

      <?php
      require('bin2hex.php');   // script (1) above
      $zpl_download = "^XA";
      $zpl_download .= "~DYE:RES,P,P,";
      $zpl_download .= $res_size;
      $zpl_download .= ",,";
      $zpl_download .= $res_string;
      $zpl_download .= "^XZ";
      ?>
      
    3. compose a ZPL script to print the downloaded file:

      <?php
      $zpl_print = "^XA";
      $zpl_print .= "^FO50,50";
      $zpl_print .= "^IME:RES.PNG";
      $zpl_print .= "^XZ";
      ?>
      
    4. write a PHP script requiring scripts (2) and (3) above to send $zpl_download and $zpl_print to the printer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 LineageOs-21.0系统编译问题
  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力