Looking for the proper code to print from php web page to a zebra IP printer using RAW port 9100. Does anyone know if this is possible? I need to send a string in ZPL formatted output direct to ZM400 label printer. I've searched high and low, the closest I've found is this: Print directly to network printer using php
It seems very close to what I need, but when my php page hits that code, it doesn't do anything. Here's the code I used:
<?php
$handle = printer_open('\\\\192.168.2.206:9100\\');
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, "TEXT To print");
printer_close($handle);
?>
I realise this question is a little old but I recently had to perform this exact task and here is how I did it. Main server is a Cloud-Based PHP server which is not on the local network. On the local network we have another machine which is simply running WAMP and this script, the Zebra printer itself is also on the local network at IP 192.168.1.201:
<?php
/*
* File Allows printing from web interface, simply connects to the Zebra Printer and then pumps data
* into it which gets printed out.
*/
$print_data = $_POST['zpl_data'];
// Open a telnet connection to the printer, then push all the data into it.
try
{
$fp=pfsockopen("192.168.1.201",9100);
fputs($fp,$print_data);
fclose($fp);
echo 'Successfully Printed';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Then, on the webpage generated by the cloud server we have some code which simply does an Ajax POST to the server on the local network, posting in the zpl_data to be printed.
Edit 2017
We've now moved things over to run through PrintNode (https://www.printnode.com/). We've found it to be really good so far, and allows us to print all kinds of documents without needing to use our own proxies, and also provide a whitelabelled installer so it looks like our own product. I'm not affiliated with PrintNode.