printing over network from PHP app

user160108 picture user160108 · Apr 17, 2011 · Viewed 30.3k times · Source

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.

Answer

Nirmal picture Nirmal · Apr 17, 2011

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