使用 php 应用程序直接从 iis 通过服务器打印到打印机而不是浏览器到共享打印机

print directly from iis using php aplication to printer through server not browser to a shared printer

我用 PHP 语言在 iis 上编写了一个应用程序。 这个程序是食物预订。 此应用程序必须从人脸 reader 设备获取数据,然后将打印件发送到热敏打印机。 这个应用程序可以从面部 reader 设备获取数据,但我的问题是当我想将打印发送到共享的打印机时我无法实现。 事实上,我想使用 php 和 iis 将文本文件发送到共享打印机 (不是通过浏览器) 我想问你解决方案是什么?

我看了很多文章,但到现在都没有达到。 请注意,我想使用 php 和 不使用浏览器 发送打印件。 并且必须使用 php 直接发送到打印机。

系统规格:

IIS v 8.5

PHP v 5.6.31

windows 服务器 2012 r2

我测试了下面的代码,我遇到了如下问题:

1-通过excec函数直接发送打印到打印机:

exec(' notepad /PT "c:\inetpub\wwwroot\test\goodtest.txt" "\2.168.10.21\BIX"')

问题是当我使用此方法时无法在 windows 服务器 2012 r2 中发送打印。

2-通过bat文件发送: 一个包含这些代码的 bat 文件:

 notepad /P "c:\inetpub\wwwroot\test\goodtest.txt"

和一个 php 文件包含这些代码:

system("cmd /c c:\inetpub\wwwroot\test\d.bat");

代码无效。

3- 通过打印 php 扩展名发送无效。

所以请指导我如何使用 php 和 iis 而不是通过浏览器 将打印件直接发送到打印机到 共享打印机.

一些答案解释了网络打印机,但我问的是共享打印机而不是网络打印机。 非常感谢。

4 周后我找到了解决方案。 这是一种使用共享打印机的方法。 使用 mike42 escpos github 插件。

require 'vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfile;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;


$connector = new WindowsPrintConnector("smb://computername/printername");
$printer = new Printer($connector);

$printer -> text("hello world");
$printer -> text("\n");
$printer -> text("\n");
$printer -> text("hello again");
$printer -> cut();
$printer -> close();