Need help in PHP Printer script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rajsekar2u
Forum Commoner
Posts: 71
Joined: Thu Nov 20, 2008 4:23 am

Need help in PHP Printer script

Post by rajsekar2u »

Hi,
Need to print the report using php.
How to do this?
Daisy100
Forum Newbie
Posts: 6
Joined: Sat Apr 25, 2009 10:48 am

Re: Need help in PHP Printer script

Post by Daisy100 »

You could use the javascript:printPage() function and include this in the php page
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Need help in PHP Printer script

Post 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.
Last edited by McInfo on Tue Jun 15, 2010 12:15 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Need help in PHP Printer script

Post 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.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Need help in PHP Printer script

Post 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.
Post Reply