PHP Printing Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ladiesduck
Forum Newbie
Posts: 5
Joined: Fri Nov 02, 2007 4:13 pm

PHP Printing Help

Post by ladiesduck »

I am working to port over a set of Inkjet print request pages from an OS X based server to a Windows 2003 one. While I have worked out most of the bugs there are a couple that elude me. The main one that I would like help on is to fix the mechanism that automatically prints a sheet of paper with the request when it is submitted online.

The code below is what works on the OS X server:

Code: Select all

//create new file
	$ourFileName = "./uploads/order3800.txt";
	$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
 	fwrite($ourFileHandle, $print_message); 
				
	//close file
 	fclose($ourFileHandle); 				
 	//systems calls to print and delete the file called "order"
 	system("lpr ./uploads/order3800.txt");
 	system("rm ./uploads/order3800.txt");
All the code seems to work fine on the Windows server except for the line that actually prints the file. I tried replacing "lpr" with "print" but I got the error "Unable to initialize device PRN". I googled this error and followed the instructions to map the networked printer to the DOS LP1 port but it did not work. Is there either a way to fix this or a better way to print using PHP?

Thanks a ton.

Jake
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Probably because the printer is not on PRN:. Look into the parameters for lpr, but I think is would be something like:

Code: Select all

system('lpr -P HPLaserjet  ./uploads/order3800.txt');
If you can configure your installation you might be interested in installing this:

http://www.php.net/manual/en/ref.printer.php
(#10850)
ladiesduck
Forum Newbie
Posts: 5
Joined: Fri Nov 02, 2007 4:13 pm

Post by ladiesduck »

I looked up the syntax for lpr and came up with this page.

http://www.microsoft.com/resources/docu ... x?mfr=true

When I try to use just

Code: Select all

system(lpr -P <printername> filename)
it gives me the below error message.

Sends a print job to a network printer Usage: lpr -S server -P printer [-C class] [-J job] [-o option] [-x] [-d] filename Options: -S server Name or ipaddress of the host providing lpd service -P printer Name of the print queue -C class Job classification for use on the burst page -J job Job name to print on the burst page -o option Indicates type of the file (by default assumes a text file) Use "-o l" for binary (e.g. postscript) files -x Compatibility with SunOS 4.1.x and prior -d Send data file first

When I try to include a server the printer is hosted on like so

Code: Select all

system(lpr -S <server IP> -P <printername> filename)
I get no error message but it does not print.

What am I doing wrong?
ladiesduck
Forum Newbie
Posts: 5
Joined: Fri Nov 02, 2007 4:13 pm

Post by ladiesduck »

Does anyone think they could help me on the syntax for this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Did you replace "server ip", "printername" and "filename" with the appropriate values?

(I had to ask)
ladiesduck
Forum Newbie
Posts: 5
Joined: Fri Nov 02, 2007 4:13 pm

Post by ladiesduck »

Hahah I understand.

I replaced the IP with our Papercut server that the printer is hosted on, the printer with the queue name on that server, and the filename with the filename.
ladiesduck
Forum Newbie
Posts: 5
Joined: Fri Nov 02, 2007 4:13 pm

Post by ladiesduck »

Sorry to keep harping on this but I still don't have an answer to my printing question.

Anyone?
Post Reply