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.

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

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B