I have a question that has been troubling me for at least 3 weeks now. I need to print some data to a printer using php. I have data saved into a $print_output
You have several options to print with PHP on Windows:
Because PHP 5.2.0 is outdated, it's quite hard to find compiled extension. You might try to drop in the php_printer extension for 5.2.8:
http://downloads.php.net/pierre/php_printer-cvs-20081215-5.2.8-nts-Win32.zip
Add to your php.ini:
extension=php_printer.dll
Recent version might be found at Pierre's download site: http://downloads.php.net/pierre/
An alternative solution is to use the windows command "print".
See http://technet.microsoft.com/en-us/library/cc772773%28v=ws.10%29.aspx
exec("print /d:\\192.168.1.33_4\\Printer_Office c:\accounting\report.txt);
$fp=pfsockopen("192.168.1.201",9100);
fputs($fp,$print_data);
fclose($fp);
For anyone who is having the same trouble, I figured out I can simply push the data using socket programming as follows. The ip address below is my printer's ip address. You can telnet into your printer to make sure the connection works beforehand if you'd like.
if(isset($_POST['order'])){
$print_output= $_POST['order'];
}
try
{
$fp=pfsockopen("192.168.1.33", 9100);
fputs($fp, $print_output);
fclose($fp);
echo 'Successfully Printed';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}