Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Would it be possible to create a php script on a local server that could handle printing?

I'm not sure it's possible, but am curious....

I'm thinking... create a local printer, use custom port TCP/IP port that points to a PHP script that processes the job. The port protocol can be LPR and using XPS driver.

I'm guessing that with this config, if I print, something will be sent to the php script. But how would I know? I can't wrap my head around how this data would come to the script. I'm used to thinking in terms of $_POST... Does it write to a spool file? What happens? How can I even print out the data to the screen or something to see what's happening?

There's this phpclass class but I'm unsure if it's even barking up the right ally.

Any ideas?

Thanks.

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

In-short... Not without an insane amount of work. It is possible to make php scripts run as a service, and accept connections on specific ports, and handle all the raw-data back & forth emulating a LPR service. From there, sure, it is possible to interpret all of the print commands to emulate any driver of your choice... and in turn process the page into some sort of output for whatever purpose you desire. Adding support for XPS... is yet another HUGE undertaking, as it's not very well documented, and only Microsoft supports it.

I seriously doubt you would want to invest that much time & money into such a HUGE undertaking.

share|improve this answer
    
Does the above-mentioned PHP class alleviate some of that work? I mean does it have to act as a service? Can't it handle a stream and spit that out onto paper? I think I'm missing some fundamentals here... off to google... thanks! –  stormdrain Apr 28 '11 at 18:51
1  
It appears that class is used to send a print job to a LPR service. I doubt it will help you in any way. You need PHP to behave as an LPR service, so you can setup a "printer" in windows to print to it. Other alternative options may include using a 3rd party library like the Black-Ice printer driver blackice.com/Printer%20Drivers/PrinterDriverProducts.htm which is a complete printer driver & framework for developers to integrate printing capabilities into applications. –  TheCompWiz Apr 29 '11 at 13:13
add comment

If you are on a *nix system you may be able to add a print filter command that reads data from standard input by adding a :if= entry to the /etc/printcap file. You can convert postscript to plain text with utilities like pstotext or some other ghostscript things.

share|improve this answer
    
The php script would indeed be on linux. But what I am confused about is what is "standard input"? What sends data to printcap? Thanks. –  stormdrain Apr 28 '11 at 18:53
    
standard input is an input channel between the program and it's environment. For example when you run a unix command and give it some information on the command line, the unix command is reading that from standard input. en.wikipedia.org/wiki/Standard_streams –  pyasi Apr 28 '11 at 20:26
    
the /etc/printcap file is the configuration file for the linux printer daemon, lpd. A unix machine running lpd can act as a print server to your desktop client. tldp.org/HOWTO/Printing-HOWTO –  pyasi Apr 28 '11 at 20:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.