LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2003, 01:25 PM   #1
Don Lag
LQ Newbie
 
Registered: Apr 2003
Posts: 1

Rep: Reputation: 0
printing through lpr from php


Hello all :-)

I need to generate printouts of data (on a laser printer) from a PHP app running on Apache/Linux. Unfortunately I'm no Linux expert so I've run into problems that I have no idea how to solve an have been unable to find solutions thus far.

This is what I'm doing so far:

1. Generate the Postscript code for the printouts.
2. Open a process to the lpr using proc_open() with the following command:
lpr -P 128.3.1.5:dp65 -J Cartas --stdin --nodialog

I previously installed the rlpr package on the server and have been able to print static postscript files succesfully on the host. "Cartas" is the intended name for the print job.

I open the process with a pipe for the process input, and files for the output and error stream.

3. Pipe the generated postscript code to the opened process.
4. Close everything.

On step 4 I get an exit value of 1 (not OK).
When I check the file set for error output it has the following line: cannot connect to X server.

I get no type of PHP error and the generation of the postscript code is ok (I checked it independently) and I'm pretty sure of handling the whole process openening with pipes and files correctly. In other words, I'd consider the PHP code to be ok.

I'm guessing the lpr command I have installed is trying to open sort of window and can't. When printing from command line with the -- nodialog option I will still get a confirmation window saying the jobs have been sent to printer. It might be the command is trying to open this final confirmation window.

I could try to install CUPS but I'd rather leave that as a very final option, since that would mean (AFAIK) installing stuff on the printer host; and I'd rather not.

My questions are:
Does my guess seem right (X-Windows problems)?
Are there any options for the lpr command I might be missing? (doesn't seem so according to the command's --help)
Are there any shell-level "modifiers" or operators that would shut off X-Windows operations in a process?
Is there any other scheme for printing that I could try?

I really appreciate any answer, suggestion or comment.
 
Old 04-01-2003, 02:31 PM   #2
bahamat
Member
 
Registered: Mar 2003
Distribution: Debian
Posts: 158

Rep: Reputation: 30
You're specifying the printer incorrectly.

It looks like you're trying to print to a printer definition on a remote host. What you should do instead is create a local printcap entry that sends the job to the remote printer and specifiy the local definition with -P.
 
Old 06-02-2003, 06:07 PM   #3
dwalbeck
LQ Newbie
 
Registered: Jun 2003
Posts: 1

Rep: Reputation: 0
Are You going to use a 'exec' or 'system' in your php to make the call to the printer? Seems like a cumbersome method if you are just printing a local document.

If you are using PHP 4.0.4 or greater, there are a number of built-in commands that you can use to select printers and send jobs.

http://www.php.net/manual/en/ref.printer.php

It's much easier to do it in Perl thought if you really want to have some robust ability.

-Davey
 
Old 06-03-2003, 12:15 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Quoting signature of bahamat
If you think XP isn't based on DOS open a "console" and type mem
Though I'm not exactly an XP enthousiast, I do think the "console" is just doing a good job here emulating DOS...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LPR Printing is cut off LazyTux Linux - Newbie 1 10-20-2005 02:40 AM
Setting up lpr and printing in gentoo 1.4 over network TwoSheds Linux - General 1 02-07-2004 10:48 AM
CUPS and LPR printing carlmarshall Linux - Newbie 2 01-23-2004 01:17 PM
lpr printing working but not everywhere ewinger Linux - Networking 0 06-04-2003 05:02 PM
Printing from lpr to plain text DoubleLetter Linux - General 2 07-19-2002 11:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration