printing over network from PHP app

风格不统一 提交于 2019-11-28 07:02:55

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

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.

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

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...";
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!