title: PHP print to printer (local / network) directly (stuck in print spooler)
body: <p>Ok, I am using PHP 5.4 and I want to print directly from web server to printer.  I am using PHP module php_printer.dll.</p>
  
  <p>The function is work well.  And I see in printer queue, the data is in, but hang in status "sent to printer"</p>
  
  <p>Here is the code</p>
  
  <pre><code>        $printerList = printer_list(PRINTER_ENUM_LOCAL);
          var_dump($printerList);
          $printerName = $printerList[0]['NAME'];
          echo $printerName;
          $printer = $printerName;
          if($ph = printer_open($printer)) {
             $content = "hello";
  
             // Set print mode to RAW and send PDF to printer
             printer_set_option($ph, PRINTER_MODE, "RAW");
             printer_write($ph, $content);
             printer_close($ph);
          }
          else "Couldn't connect...";
  </code></pre>
  
  <p>There is no error in screen or logs file in Apache, so i assume the PHP code run well.  And I see the data is in Windows print spooler.  The problem is it stuck in there, and it cannot produce the output from printer.</p>
  
  <p>I assume the problem is because the windows permission problem (I am using windows 8, test in windows 7 or XP cannot work too).  I have 4 test printer: 1. HP Laser Jet 401, 2. PDF Printer, 3. Windows Fax, 4.  XPS document writer.</p>
  
  <p>My computer cannot print to all the 4 printers.  I test in other computer, it can print to printer number 1, but the other cannot.</p>
  
  <p>The status is only "Sent to printer".  If it is printing, the status is "spooling"</p>
  
  <p>I attach the screenshot the queue data in spool printer.  <img src="https://i.stack.imgur.com/BzcDt.jpg" alt="Sent to printer status"></p>
  
  <p>And this is the screenshot that success spooler (I test with print normal, ctrl+p and print) <img src="https://i.stack.imgur.com/PF4n9.jpg" alt="Spooling"></p>
  
  <p>Any help will be appreciated.  Thanks!</p>