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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵