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.
The function is work well. And I see in printer queue, the data is in, but hang in status "sent to printer"
Here is the 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...";
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.
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.
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.
The status is only "Sent to printer". If it is printing, the status is "spooling"
I attach the screenshot the queue data in spool printer. 
And this is the screenshot that success spooler (I test with print normal, ctrl+p and print) 
Any help will be appreciated. Thanks!
I got the answer, the problem is you have to add this in the beginning
printer_start_doc($ph, "Start Doc");
and this before printer_close
printer_end_doc($ph);
Cannot print without start and end doc.
I am just wondering why I still can print to printer number 1 at other computer, but does not use that start and end doc PHP command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With