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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度