use*_*191 4 php windows printing
我有一个问题困扰了我至少 3 周。我需要使用 php 将一些数据打印到打印机。我将数据保存到一个$print_output变量中,我知道我的数据很好,因为当我通过电子邮件发送它时,它显示了应该显示的所有内容。
好吧,我尝试编写这段代码,我以为可以测试它,但不确定它是否会起作用。
$handle = printer_open("\\\\192.168.1.33_4\\Printer_Office");
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$print_output);
printer_close($handle);
Run Code Online (Sandbox Code Playgroud)
好吧,结果我没有安装 php_printer.dll 扩展,我被告知不要重新编译 php 来添加它。
我想要做的只是将存储在$print_output同一网络上的打印机中的数据打印出来。我不想使用 javascript 功能,window.print()因为我无法弹出打印对话屏幕。
有没有人有任何信息可以为我指明正确的方向?或者另一种不使用php的printer_open功能而直接将少量数据直接打印到打印机的方法?
对于遇到同样问题的任何人,我发现我可以简单地使用套接字编程推送数据,如下所示。下面的ip地址是我打印机的ip地址。如果您愿意,您可以 telnet 到您的打印机,以确保连接能正常工作。
if(isset($_POST['order'])){
$print_output= $_POST['order'];
}
try
{
$fp=pfsockopen("192.168.1.33", 9100);
fputs($fp, $print_output);
fclose($fp);
echo 'Successfully Printed';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Run Code Online (Sandbox Code Playgroud)
在 Windows 上使用 PHP 进行打印有多种选择:
由于 PHP 5.2.0 已经过时,因此很难找到已编译的扩展。您可以尝试添加 5.2.8 的 php_printer 扩展:
http://downloads.php.net/pierre/php_printer-cvs-20081215-5.2.8-nts-Win32.zip
添加到您的 php.ini:
extension=php_printer.dll
Run Code Online (Sandbox Code Playgroud)
最新版本可以在 Pierre 的下载站点找到: http: //downloads.php.net/pierre/
另一种解决方案是使用 Windows 命令“print”。
请参阅http://technet.microsoft.com/en-us/library/cc772773%28v=ws.10%29.aspx
exec("print /d:\\192.168.1.33_4\\Printer_Office c:\accounting\report.txt);
Run Code Online (Sandbox Code Playgroud)
$fp=pfsockopen("192.168.1.201",9100);
fputs($fp,$print_data);
fclose($fp);
Run Code Online (Sandbox Code Playgroud)