使用php直接打印到网络打印机 [英] Print directly to network printer using php

查看:663
本文介绍了使用php直接打印到网络打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用php将页面打印到网络打印机.
但这在本地打印机上有效. 我已经安装了php_printer.dll并在php.ini中启用了 以下是代码:

I am unable to print a page to a network printrer using php.
But this works if it is a local printer. I have installed php_printer.dll and enabled in php.ini The following is the code:

//$handle  =  printer_open("Send To OneNote 2007"); ///This Works

$handle = printer_open('\\\\192.168.0.8\\Canon MF4320-4350'); 
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, "TEXT To print");
printer_close($handle);

显示错误

警告:printer_write()[function.printer-write]:无法分配 第16行的E:\ Server \ xampp \ htdocs \ Kiosk \ Admin \ print.php中的printerjob [5]

Warning: printer_write() [function.printer-write]: couldn't allocate the printerjob [5] in E:\Server\xampp\htdocs\Kiosk\Admin\print.php on line 16

推荐答案

如果使用命令行PHP(CLI),则可以在网络打印机上进行打印.顺便说一下,您的$ addr是正确的.

If you used the command line PHP (CLI) the printing to network printers would work. Your $addr is correct by the way.

当您将PHP与Apache结合使用时,问题就出在PHP上.在Windows中,您的php脚本将在用户SYSTEM下运行.由于安全方面的考虑,SYSTEM看不到所有网络资源.

The issue lies with PHP when you combine it with Apache. In windows, your php scripts would run under the user SYSTEM. Because of security concerns, all network resources are not visible to SYSTEM.

要解决此问题,请创建一个具有管理员特权(或至少具有网络资源"可见性)的新用户.在Windows中,如果将Apache作为服务运行,请单击Apache Service Monitor中的SERVICE按钮.在Apache 2.2下,右键单击属性.在登录"选项卡下,将用户从"SYSTEM"更改为您新创建的用户帐户.重新启动Apache.您应该现在就可以运行PHP脚本以打印到网络打印机.

To resolve this problem, create a new user with admin privileges (or at least with Network Resource visibility). In Windows, if you run Apache as a service, click on the SERVICE button in the Apache Service Monitor. Under Apache 2.2, right click on properties. Under the LOGIN tab, change the user from SYSTEM to your newly created user account. Restart Apache. You should be able to run your PHP script to print to network printers now.

这篇关于使用php直接打印到网络打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆