Page 1 of 1

Need help in PHP Printer script

Posted: Sat Apr 25, 2009 9:17 am
by rajsekar2u
Hi,
Need to print the report using php.
How to do this?

Re: Need help in PHP Printer script

Posted: Sat Apr 25, 2009 11:02 am
by Daisy100
You could use the javascript:printPage() function and include this in the php page

Re: Need help in PHP Printer script

Posted: Sat Apr 25, 2009 3:47 pm
by McInfo
PHP Manual: Printer

The printer functions are Windows-only.

Make sure php_printer.dll is enabled in php.ini.

Here is a simple example.

Code: Select all

<?php
if (!function_exists('printer_open'))
    die('<p style="color: red">No printer support detected.</p>');
else
    echo '<p style="color: green">Printer support detected.</p>';
 
$printer_name = '\\\\192.168.0.1\\Canon S300';
if ($ph = printer_open($printer_name))
{
    echo '<p style="color: green">Successfully opened printer: '.$printer_name.'</p>';
   
    $text = 'Text to send to the printer.';
   
    echo "<pre>$text</pre>";
   
    if (printer_write($ph, $text))
        echo '<p style="color: green">Successfully sent text to printer.</p>';
    else
        echo '<p style="color: red">Failed to send text to printer.</p>';
   
    printer_close($ph);
}
else
    echo '<p style="color: red">Could not open printer: '.$printer_name.'</p>';
?>
I don't know enough about this to troubleshoot for you.

Edit: This post was recovered from search engine cache.

Re: Need help in PHP Printer script

Posted: Sat Apr 25, 2009 6:31 pm
by John Cartwright
The PHP print extension is for printing on the server machine, not the client machine. You will need to use javascript to prompt the client the print.

Re: Need help in PHP Printer script

Posted: Sat Apr 25, 2009 6:51 pm
by McInfo
John Cartwright wrote:The PHP print extension is for printing on the server machine, not the client machine.
That condition was not defined in the request. I probably should have mentioned that in my response, though.

Edit: This post was recovered from search engine cache.