Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
error_reporting(E_ALL);


include("PrintSend.php");

include("PrintSendLPR.php");


echo "

PrintSendLPR example

";

$lpr = new PrintSendLPR();


$lpr->setHost("127.0.0.1"); //Put your printer IP here

$lpr->setData("C:\your\path\test.txt"); //Path to file, OR string to print.

echo
$lpr->printJob("someQueue");//If your printer has a built-in printserver, it might just accept anything as a queue name.

echo "

Debug

".
$lpr->getDebug()."
";


?>

What I have tried:

I tried printer_open(); with different variations but nothing worked
Posted
Updated 23-Feb-16 2:54am

1 solution

I haven't used printing with PHP, but try this
$printer = "printername"); //or try $printer = "\\\\localhost\\printername"); 
if($ph = printer_open($printer)) 
{ 
   // Get file contents 
   $fh = fopen("filename.ext", "rb"); 
   $content = fread($fh, filesize("filename.ext")); //your path for the file goes in the place of 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..."; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900