PHP 5.6.0 released

Funções da Printer

Índice

add a note add a note

User Contributed Notes 4 notes

up
0
mdwyer at timestreamtech dot com
7 years ago
I was able to print nice looking reports (under unix) by sending out formatted text out through 'enscript'.  The various configuration options on enscript took care of fonts and headers etc.  The result was a postscript file which I just sent to the server's local printer.

One could also pipe it through a PS to PDF filter and send it back to the user, I suppose.

For another job, I learned how to write postscript and just wrote directly to postscript files.  Learning how to write postscript is probably only marginally harder than learning how to use this API, and is probably more portable.
up
0
arne dot briesenick at soxabo dot de
9 years ago
Printing in UN*X is possible too:

<?php
function lpr($STR,$PRN) {
 
$prn=(isset($PRN) && strlen($PRN))?"$PRN":C_DEFAULTPRN ;
 
$CMDLINE="lpr -P $prn ";
 
$pipe=popen("$CMDLINE" , 'w' );
  if (!
$pipe) {print "pipe failed."; return ""; }
 
fputs($pipe,$STR);
 
pclose($pipe);
}
// lpr()
?>

You pipe the stream/string/char/sign whatever to the system. In the example shown above you have to add at least the string for printing in the function call. The second arg is a printer name which if you don't set will be set to the C_DEFAULTPRN. This is a constant definition from an ini file.

Hope this will help to save a lot of time ;-)
up
0
jwlash at acm dot org
11 years ago
I have noticed the for unix based systems you can also do this:

system("lp $filename")

:)
up
-1
bertATnerdstockDOTorg
11 years ago
If you want to address the printer from your PHP-application in a Un*x environment:
This is possible if you use a different method.
In Unix it would not be logical to address your printer directly from php, but you could for instance generate a PDF-file with PDFlib (or a textfile, or a PNG/JPEG image with GD or what have you) and write it from your php-script to a directory that you use as a "printer-outbox."

Next, you write a shellscript that calls some unix tool to print all pdf or other documents in your "outbox" directory and then deletes all files in that directory.

Then you use crontab to run this script every minute or as often as you think it's neccessary.

You could of course also call the shellscript from your php-application with exec() but you'll probably want to avoid using exec() and the like for security reasons.
To Top