tags:

views:

318

answers:

2

Hi,

I want to print some records using PHP-Gtk.

I am using following code but it did not worked.

$handle = fopen("PRN", "w"); 
fwrite($handle, 'text to printer'); 
fclose($handle);

Please help me Thanks Rahul

A: 

You need to know which device your printer is and this depends on your operating system.

Your code assumes the printer to be available at the PC's parallel port. It is there?

tuergeist
+2  A: 

Asumming you are asking this for a Windows environment i think you should have a look at the printer functions on php.net

The printer functions are part of the PECL extensions and it can be downloaded from php.net (Link goes to PECL 5.2.6 that works with PHP 5.2.11)

The printer functions in PHP are not very useful to me, so i tend to use different techniques to create a PDF and have it displayed by the default PDF reader (usually Adobe Reader) that has so much better printing support. But i can think of cases when that is not an accepted behaviour.

Code example from php.net (prints to default printer):

$handle = printer_open();
printer_start_doc($handle, "My Document");
printer_start_page($handle);

$font = printer_create_font("Arial", 148, 76, PRINTER_FW_MEDIUM, false, false, false, -50);
printer_select_font($handle, $font);
printer_draw_text($handle, "PHP is simply cool", 40, 40);
printer_delete_font($font);

printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
Peter Lindqvist
It's worth noting that this is a PECL package, not included in PHP itself.
HalfBrian
You're absolutely right, good point!
Peter Lindqvist