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.
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
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);
}
?>
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";
?>
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";
?>
write a PHP script requiring scripts (2) and (3) above to send $zpl_download
and $zpl_print
to the printer.