Search code examples
phpwindowsprintinglocalhostintranet

use printer via php


I have four computers and one printer in Intranet and I installed WAMP on one of Windows machines. Now I want to execute PHP script, from window machine browser (or via Ajax etc) to print data. I need to know will it be possible? if yes then how?


Solution

  • Use printer functions:

    <?php 
        $printer = "\\\\hostname\\printername"); 
        if($ph = printer_open($printer)) { 
           $fh = file_get_contents('myfile.txt');
           printer_set_option($ph, PRINTER_MODE, "RAW"); 
           printer_write($ph, $content); 
           printer_close($ph); 
        } else {
            echo "Can't connect to printer"; 
        }
    ?>