Forum Moderators: coopster

Message Too Old, No Replies

How to send to printer on Windows XP?

         

MTKilpatrick

9:24 am on Sep 27, 2005 (gmt 0)

10+ Year Member



I've just written a script that processes a Postscript file before sending it to the printer. I'm doing this with a printer port redirection using Redmon to execute the PHP script with c:\php\php.exe -c MyScript.exe. The postscript comes in as STDIN to the script from the printer driver.

Everything is fine except one thing. I simply can't work out how to send the modified Postscript data to the printer! Any help, please?

I have a Windows XP machine with PHP and Apache, and a HP 5100 LaserJet printed (PCL and PS) on a JetDirect wireless server card.

This means that on the Windows command line I can do this:

lpr -S 192.168.1.4 -P HPLaserJet5100 filename

as well as print from within applications by the normal method.

However, I can't work out what PHP commands I should use to send a file, or a PHP string var (containing the entire Postscript data), to the printer! I can't pipe data in an lpr command, can I? I tried printer_open() printer_write(), etc, but that just made the printer print the Postscript as raw text without interpreting it! How do I communicate properly with the printer?

thanks,

Michael

chrisjoha

9:32 am on Sep 27, 2005 (gmt 0)

10+ Year Member



Are you sending the correct headers with the data? Since it is not processing the postscript it might indicate that the printer thinks it is receiving pure text.

Also, have you concidered the option of writing a temporary file, send it to the printer and then delete it?

MTKilpatrick

11:52 am on Sep 27, 2005 (gmt 0)

10+ Year Member



Ah, I've just found that this works:

$handle = printer_open();
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$myfile);
printer_close($handle);

There isn't enough in the manual to tell me that I might need to set the options. It's not very detailed compared to the other sections of the manual.

Michael