|
Printer FunctionsThese functions are only available under Windows 9.x, ME, NT4 and 2000. They have been added in PHP 4.0.4. This » PECL extension is not bundled with PHP.
Windows users must enable
The behaviour of these functions is affected by settings in Table 270. Printer configuration options
This extension defines handles to a printer connection, to a brush, to a font and to a pen. Table of Contents
Code Examples / Notes » ref.printerjason
You can print in XP. AND, you can print to a shared printer with XP. The drivers for the printer MUST be installed on ther server as well as on the computer you wish to print with. Also, the printer must be shared on the client computer. I am using a Zebra LP2844 Thermal Barcode Printer in my application. I am running XP Pro,Apache 1.3.27, PHP 4.3+. Here is a function I use in our churches checkin system. I use this to print directly to our printer with out having to use any Javascript. First, i give the function the name of the shared printer. Second, I get the client computers host name. You could use just REMOTE_ADDR too I suppose. Then I return a correctly formatted Windows path to the shared printer for the function getPrinter($SharedPrinterName) { global $REMOTE_ADDR; $host = getHostByAddr($REMOTE_ADDR); return "\\\\".$host."\\".$SharedPrinterName; } $handle = printer_open(getPrinter("Eltron")); So, as long as you KNOW the computers are suppose to have a shared printer called "Eltron", you're all set to start sending info to the printer with the other Printer functions. -j arne dot briesenick
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 ;-) macagomez
Please notice that what is printed is NOT measured in pixels, it is measured in pronter's dots. Apply to fonts, coordinates and bit maps. bertatnerdstockdotorg
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. mdwyer
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. jwlash
I have noticed the for unix based systems you can also do this: system("lp $filename") :) extremesanity
I have gotten very reliable printing using this set of functions coupled with Windows 2000, IIS, the PECL extension, and the php_printer.dll. Basically I have a linux web server that sends a request to the windows 2000 IIS web server (acting as the role of print server) sending the information to be printed in the query string. I use this primarily for printing barcoded labels, where the barcode itself is a barcode font found on the web. I got terrible reliability out of all versions of apache running on windows 2000 and xp. |
Change Language.NET Functions Apache-specific Functions Alternative PHP Cache Advanced PHP debugger Array Functions Aspell functions [deprecated] BBCode Functions BCMath Arbitrary Precision Mathematics Functions PHP bytecode Compiler Bzip2 Compression Functions Calendar Functions CCVS API Functions [deprecated] Class/Object Functions Classkit Functions ClibPDF Functions [deprecated] COM and .Net (Windows) Crack Functions Character Type Functions CURL Cybercash Payment Functions Credit Mutuel CyberMUT functions Cyrus IMAP administration Functions Date and Time Functions DB++ Functions Database (dbm-style) Abstraction Layer Functions dBase Functions DBM Functions [deprecated] dbx Functions Direct IO Functions Directory Functions DOM Functions DOM XML Functions enchant Functions Error Handling and Logging Functions Exif Functions Expect Functions File Alteration Monitor Functions Forms Data Format Functions Fileinfo Functions filePro Functions Filesystem Functions Filter Functions Firebird/InterBase Functions Firebird/Interbase Functions (PDO_FIREBIRD) FriBiDi Functions FrontBase Functions FTP Functions Function Handling Functions GeoIP Functions Gettext Functions GMP Functions gnupg Functions Net_Gopher Haru PDF Functions hash Functions HTTP Hyperwave Functions Hyperwave API Functions i18n Functions IBM Functions (PDO_IBM) IBM DB2 iconv Functions ID3 Functions IIS Administration Functions Image Functions Imagick Image Library IMAP Informix Functions Informix Functions (PDO_INFORMIX) Ingres II Functions IRC Gateway Functions PHP / Java Integration JSON Functions KADM5 LDAP Functions libxml Functions Lotus Notes Functions LZF Functions Mail Functions Mailparse Functions Mathematical Functions MaxDB PHP Extension MCAL Functions Mcrypt Encryption Functions MCVE (Monetra) Payment Functions Memcache Functions Mhash Functions Mimetype Functions Ming functions for Flash Miscellaneous Functions mnoGoSearch Functions Microsoft SQL Server Functions Microsoft SQL Server and Sybase Functions (PDO_DBLIB) Mohawk Software Session Handler Functions mSQL Functions Multibyte String Functions muscat Functions MySQL Functions MySQL Functions (PDO_MYSQL) MySQL Improved Extension Ncurses Terminal Screen Control Functions Network Functions Newt Functions NSAPI-specific Functions Object Aggregation/Composition Functions Object property and method call overloading Oracle Functions ODBC Functions (Unified) ODBC and DB2 Functions (PDO_ODBC) oggvorbis OpenAL Audio Bindings OpenSSL Functions Oracle Functions [deprecated] Oracle Functions (PDO_OCI) Output Control Functions Ovrimos SQL Functions Paradox File Access Parsekit Functions Process Control Functions Regular Expression Functions (Perl-Compatible) PDF Functions PDO Functions Phar archive stream and classes PHP Options&Information POSIX Functions Regular Expression Functions (POSIX Extended) PostgreSQL Functions PostgreSQL Functions (PDO_PGSQL) Printer Functions Program Execution Functions PostScript document creation Pspell Functions qtdom Functions Radius Rar Functions GNU Readline GNU Recode Functions RPM Header Reading Functions runkit Functions SAM - Simple Asynchronous Messaging Satellite CORBA client extension [deprecated] SCA Functions SDO Functions SDO XML Data Access Service Functions SDO Relational Data Access Service Functions Semaphore SESAM Database Functions PostgreSQL Session Save Handler Session Handling Functions Shared Memory Functions SimpleXML functions SNMP Functions SOAP Functions Socket Functions Standard PHP Library (SPL) Functions SQLite Functions SQLite Functions (PDO_SQLITE) Secure Shell2 Functions Statistics Functions Stream Functions String Functions Subversion Functions Shockwave Flash Functions Swish Functions Sybase Functions TCP Wrappers Functions Tidy Functions Tokenizer Functions Unicode Functions URL Functions Variable Handling Functions Verisign Payflow Pro Functions vpopmail Functions W32api Functions WDDX Functions win32ps Functions win32service Functions xattr Functions xdiff Functions XML Parser Functions XML-RPC Functions XMLReader functions XMLWriter Functions XSL functions XSLT Functions YAZ Functions YP/NIS Functions Zip File Functions Zlib Compression Functions |