5

我用 PHP 构建了一个 POS(销售点)应用程序,可以直接打印到热敏打印机。在大多数情况下,我使用 WAMP 在本地网络服务器上运行应用程序。

部分打印代码为:

$printer = "\\\\localhost\\TM-T88V";

// Open connection to the thermal printer
$fp = fopen($printer, "w");
if (!$fp){
  die('no connection');
}

$data = " PRINT THIS ";

// Cut Paper
$data .= "\x00\x1Bi\x00";

if (!fwrite($fp,$data)){
  die('writing failed');
}

只要 PC 连接到网络,此代码就可以正常工作。我可以使用 fopen 和 "LOCALHOST" 或 "COMPUTER-NAME" 让 PHP 连接到共享打印机(在同一台电脑上或网络中的电脑上): fopen("\\localhost\TM-T88V" ,'w');

如果我断开电脑与网络的连接,PHP 将无法再连接到 \\localhost 或 \\COMPUTER-NAME。

我尝试过类似:fopen('TM-T88V')、fopen('\\.\TM-T88V'),但我不断收到“[function.fopen]:无法打开流:没有这样的文件或目录……”。

如何在没有活动网络连接的情况下连接到本地(共享)打印机(最好按名称)?

4

2 回答 2

3

你试过fopen("PRN", "w")吗?

于 2012-04-22T16:41:09.270 回答
0

这是我在 PHP 中用于打印作业的代码片段:

$handle = printer_open('Printer Name in windows here');

if($handle) { // Make sure the printer is present before sending the job
// print job here
}
于 2016-08-25T09:57:58.520 回答