PHP 到 Zebra 打印机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3766228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP to Zebra Printer
提问by Nirmal
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.
我将这台 Zebra ZM400 打印机连接到网络 ( 192.168.1.50
)。我正在尝试直接从 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.
这就是这个想法,我只是被卡住了,没有任何方法可以做到这一点。我尝试了file_put_contents('192.168.1.50', $content)
但没有成功。
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:
我使用 LPR 协议打印。无需安装驱动程序或任何东西。PHP 5 的 LPR 打印类可以从这里下载:
http://www.phpclasses.org/package/2540-PHP-Abstraction-for-printing-documents.html
http://www.phpclasses.org/package/2540-PHP-Abstraction-for-printing-documents.html
采纳答案by Mitch Dempsey
I'm pretty sure just pushing text content over a socket will not work at all.
我很确定只是将文本内容推送到套接字上根本不起作用。
You will need to print over lpr is my guess. Install a print server like CUPS and you can send it using that...
你需要打印 lpr 是我的猜测。安装一个像 CUPS 这样的打印服务器,你可以使用它发送它......
回答by Edwin
I had a similar issue where I was using a java program to print to a zebra printer without a print driver, and wanted to recreate this using PHP. It was bugging me that I couldn't find the answer. Through some packet capturing with Wireshark comparing the two, I felt that it was possible. I finally stumbled into the solution (at least for me). This will print a label to a networked Zebra printer directly from a PHP page without the need for a driver.
我有一个类似的问题,我使用 java 程序在没有打印驱动程序的情况下打印到 zebra 打印机,并想使用 PHP 重新创建它。找不到答案让我很烦恼。通过Wireshark的一些抓包比较两者,我觉得这是可能的。我终于偶然发现了解决方案(至少对我而言)。这将直接从 PHP 页面将标签打印到联网的 Zebra 打印机,无需驱动程序。
<?php
error_reporting(E_ALL);
/* Get the port for the service. */
$port = "9100";
/* Get the IP address for the target host. */
$host = "172.17.144.89";
/* construct the label */
$mrn = "123456";
$registration_date = "03/13/2013";
$dob = "06/06/1976";
$gender = "M";
$nursing_station = "ED";
$room = "ED01";
$bed = "07";
$lastname = "Lastname";
$firstname = "Firstname";
$visit_id = "12345678";
$label = "q424\nN\n";
$label .= "A10,16,0,3,1,1,N,\"MR# " . $mrn . " ";
$label .= $registration_date . "\"\n";
$label .= "B10,43,0,3,2,4,50,N,\"" . $mrn . "\"\n";
$label .= "A235,63,0,3,1,1,N,\" ";
$label .= $dob . " ";
$label .= $gender . "\"\n";
$label .= "A265,85,0,3,1,1,N,\" ";
$label .= $nursing_station . " ";
$label .= $room . "-";
$label .= $bed . "\"\n";
$label .= "A10,108,0,3,1,1,N,\"";
$label .= $lastname . ",";
$label .= $firstname;
$label .= "\"\n";
$label .= "A10,135,0,3,1,1,N,\" #" . $visit_id . "\"\n";
$label .= "B10,162,0,3,2,4,50,N,\"" . $visit_id . "\"\n";
$label .= "P1\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error ()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$host' on port '$port'...";
$result = socket_connect($socket, $host, $port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror (socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}
socket_write($socket, $label, strlen($label));
socket_close($socket);
?>
回答by paulmelnikow
I see you've gotten solutions using LPR and FTP, but I'm almost certain the Zebra printers will accept raw ZPL text on port 9100.
我看到您已经获得了使用 LPR 和 FTP 的解决方案,但我几乎可以肯定 Zebra 打印机将接受端口 9100 上的原始 ZPL 文本。
回答by bashman
Later?...
之后?...
If you have access to the serial port:
如果您有权访问串行端口:
LINUX:
LINUX:
$fpi = fopen('/dev/ttyS0', 'r+'); $comando = " N Q70 A40,20,0,2,1,0,N,\"xxx\" B40,40,0,1,2,6,100,N,\"$don\" A40,145,0,3,1,0,N,\"N.- $don \" A40,165,0,2,1,0,N,\"ccc\" A0,198,7,1,1,0,N,\"$fecha\" A19,198,7,1,1,0,N,\"fasdfas\" P "; fwrite($fpi, $comando); fclose($fpi);
- THIS WORK FINE
- 这工作正常
回答by Ryan
I have created a file in zebra language and used FTP to send the file many times in the past. just save the file and then create an ftp connection to the printer then use the put command to send the .txt file. the printer will do the rest
我用斑马语言创建了一个文件,并在过去多次使用FTP发送文件。只需保存文件,然后创建到打印机的 ftp 连接,然后使用 put 命令发送 .txt 文件。打印机将完成剩下的工作
回答by Bluby
There is sample code on how to send ZPL directly to Zebra printers at:
有关如何将 ZPL 直接发送到 Zebra 打印机的示例代码,请访问:
https://km.zebra.com/kb/index?page=content&channel=SAMPLE_CODE&cat=ZISV_PL_ZPL
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.
我在 PHP 中没有看到任何内容,但是有一个使用 VB 通过端口 9100 直接与打印机对话的示例。
回答by cetipabo
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
这是在连接到网络的 Zebra 打印机上打印的方法:假设您的打印机位于 IP:192.168.1.50 和标准端口: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 PRINTERin it
这在任何 ZPL 兼容打印机上都能 100% 运行,而不仅仅是 Zebra。在这个例子中我们打印标签有一个大测试斑马打印机在它
回答by codaddict
Take a look at these PHP printer functions
看看这些PHP打印机功能
Note that
注意
These functions are only available under Windows 9.x, ME, NT4 and 2000.
这些功能仅在 Windows 9.x、ME、NT4 和 2000 下可用。