从 PHP 应用程序通过网络打印

发布于 2024-11-02 02:07:45 字数 138 浏览 5 评论 0原文

我有一组通过网络连接的打印机,并为每台打印机分配了静态 IP。

现在我有一个在 Linux 服务器上运行的 PHP Web 应用程序,它需要通过网络向这些打印机发送打印作业。

使用 lpr 或杯子是否可以实现这一点,我该如何进行?

I have a set of printers connect over a network with Static IP assigned to each printer.

Now i have a PHP web application running on a linux server which needs to send print jobs, to these printer over the network.

Is this possible using lpr or cups and how do i go about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别再吹冷风 2024-11-09 02:07:45

您可以从这里使用 LPR Printer 类:

http://www.phpclasses。 org/package/2540-PHP-Abstraction-for-printing-documents.html

示例:

<?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.
?>

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.
?>
无法回应 2024-11-09 02:07:45

这个问题之前已经被问过。请参阅使用 PHP 打印到网络打印机

当时给出的答案是exec("lpr -P 'printer' -r 'filename.txt');

但是,答案从未被接受,所以不确定 OP 是否认为它有帮助;它看起来确实应该这样做技巧,但这并不是一种在 PHP 中实现的直接且简单的方法,

我发现许多其他资源也推荐了这种方法的变体,

我发现 PHP 在 PECL 中有一个打印机模块。然而,它仅适用于 Windows,并且看起来维护得不好,但如果它有帮助,请在此处链接:http://www.php.net/manual/en/intro.printer.php

我认为最终的答案是 PHP 并不是真正为这种事情而设计的,并且没有内置的功能来做到这一点,但是由于您可以使用 exec() 和类似的命令来执行外部命令,所以让它工作应该不会太难,尽管不是很困难。理想的。

This question has been asked before. See print to a network printer using PHP

The answer given that time was exec("lpr -P 'printer' -r 'filename.txt');

However, the answer was never accepted so not sure whether the OP found it helpful; it certainly looks like it ought to do the trick, but it's not quite a direct and easy method of doing it from within PHP.

A number of other resources I found were also recommending variations on this approach.

Digging a bit deeper, I see PHP has got a Printer module in PECL. However it's only for Windows, and looks like it's not well maintained. But in case it helps, the link it here: http://www.php.net/manual/en/intro.printer.php

I think the answer ultimately is that PHP isn't really designed for this kind of thing, and doesn't have built-in functionality to do it. But since you can shell out to external commands using exec() and similar, it shouldn't be too hard to get it working, albeit not quite ideal.

扬花落满肩 2024-11-09 02:07:45

尝试 PHP::PRINT::IPP

它对我来说非常有效。

基本用法

 <?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();                                                          
?>

参考

Try PHP::PRINT::IPP

It worked perfectly for me.

Basic Usage

 <?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();                                                          
?>

Reference

风筝在阴天搁浅。 2024-11-09 02:07:45

我也在对此进行研究......我认为下面编写的代码可以帮助您在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...";
?>

i was also doing research on this...and i think the below written code can help you in handling printer in 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...";
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文