gpt4 book ai didi

PHP 到 Zebra 打印机

转载 作者:可可西里 更新时间:2023-10-31 22:42:18 29 4
gpt4 key购买 nike

我将这台 Zebra ZM400 打印机连接到网络 (192.168.1.50)。我正在尝试直接从 PHP 将内容推送到这台打印机。

这就是我的想法,但我无法做到这一点。我尝试了 file_put_contents('192.168.1.50', $content) 但没有成功。

如果有人能帮我解决这个问题,我将不胜感激。谢谢:-)

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

解决方案:

我使用 LPR 协议(protocol)打印。无需安装驱动程序或任何东西。 PHP 5 的 LPR 打印类可以从这里下载:

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

最佳答案

我有一个类似的问题,当时我使用 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);

?>

关于PHP 到 Zebra 打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3766228/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com