我有一组打印机通过网络连接,并为每台打印机分配了静态 IP。
现在我有一个在 linux 服务器上运行的 PHP Web 应用程序,它需要通过网络向这些打印机发送打印作业。
这可能使用 lpr 或杯子吗?我该怎么做。
我有一组打印机通过网络连接,并为每台打印机分配了静态 IP。
现在我有一个在 linux 服务器上运行的 PHP Web 应用程序,它需要通过网络向这些打印机发送打印作业。
这可能使用 lpr 或杯子吗?我该怎么做。
You could use the LPR Printer class from here:
http://www.phpclasses.org/package/2540-PHP-Abstraction-for-printing-documents.html
Example:
<?php
include("PrintSend.php");
include("PrintSendLPR.php");
$lpr = new PrintSendLPR();
$lpr->setHost("10.0.0.17"); //Put your printer IP here
$lpr->setData("C:\\wampp2\\htdocs\\print\\test.txt"); //Path to file, OR string to print.
$lpr->printJob("someQueue"); //If your printer has a built-in printserver, it might just accept anything as a queue name.
?>
这个问题以前有人问过。请参阅使用 PHP 打印到网络打印机
当时给出的答案是exec("lpr -P 'printer' -r 'filename.txt');
但是,答案从未被接受,因此不确定 OP 是否认为它有帮助;它当然看起来应该可以解决问题,但它不是从 PHP 中实现它的直接且简单的方法。
我发现的许多其他资源也推荐了这种方法的变体。
再深入一点,我看到 PHP 在 PECL 中有一个打印机模块。但是它仅适用于 Windows,并且看起来维护得不好。但如果有帮助,请在此处链接:http ://www.php.net/manual/en/intro.printer.php
我认为最终的答案是 PHP 并不是真正为这种事情而设计的,也没有内置的功能来做到这一点。但是,由于您可以使用exec()
和类似的命令来处理外部命令,因此让它工作应该不会太难,尽管不是很理想。
它对我来说非常有效。
基本用法
<?php
require_once(PrintIPP.php);
$ipp = new PrintIPP();
$ipp->setHost("localhost");
$ipp->setPrinterURI("/printers/epson");
$ipp->setData("./testfiles/test-utf8.txt"); // Path to file.
$ipp->printJob();
?>
我也在做这方面的研究......我认为下面的编写代码可以帮助你在 linux 中处理打印机
<?php
$printer = "\\\\Pserver.php.net\\printername");
if($ph = printer_open($printer))
{
// Get file contents
$fh = fopen("filename.ext", "rb");
$content = fread($fh, filesize("filename.ext"));
fclose($fh);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
printer_close($ph);
}
else "Couldn't connect...";
?>