PHP to Zebra Printer

2020-02-08 06:34发布

I have this Zebra ZM400 Printer connected to the network (192.168.1.50). And I am trying to push a content to this printer directly from PHP.

This is the idea and I am just stuck without any way to do this. I tried the file_put_contents('192.168.1.50', $content) but with no success.

Would appreciate if anyone could please help me in sorting out this. Thank you :-)

.................................................................................................................................

Solution:

I printed using the LPR Protocol. No need to install driver or anything. The LPR Printing Class for PHP 5 can be downloaded from here:

http://www.phpclasses.org/package/2540-PHP-Abstraction-for-printing-documents.html

8条回答
姐就是有狂的资本
2楼-- · 2020-02-08 07:03

This is how to print on a Zebra Printer connected to the network: Assuming your printer is at IP: 192.168.1.50 and standard port : 9100

<?php 
if(($conn = fsockopen('192.168.1.50',9100,$errno,$errstr))===false){ 
    echo 'Connection Failed' . $errno . $errstr; 
} 

$data = ' 
    ^XA 
    ^FT50,200 
    ^A0N,200,200^FDTEST^FS 
    ^FT50,500 
    ^A0N,200,200^FDZebra Printer^FS 
    ^XZ'; 

#send request 
$fput = fputs($conn, $data, strlen($data)); 

#close the connection 
fclose($conn); 
?> 

This is working 100% on any ZPL compatible printer, not only Zebra. In this Example we print a label with a big TEST ZEBRA PRINTER in it

查看更多
Animai°情兽
3楼-- · 2020-02-08 07:12

There is sample code on how to send ZPL directly to Zebra printers at:

https://km.zebra.com/kb/index?page=content&channel=SAMPLE_CODE&cat=ZISV_PL_ZPL

I didn't see any in PHP, but there is an example of talking directly to the printer via port 9100 using VB.

查看更多
登录 后发表回答