Archive

Posts Tagged ‘printing’

Printing directly from PHP

January 12th, 2009 No comments

The inherent nature of PHP makes it difficult to print directly from a PHP page.  PHP is a web based scripting language that is based on a server/client architecture.  For security reasons, PHP tries to maintain a separation from the server and any printers attached to the server.

Luckily for us, this separation is not perfect, and there are ways around it.

Two possible methods for printing directly from PHP

  • Use the embedded printer functions in PHP (windows only)
  • Use the embedded program execution functions in PHP to execute scripts (linux or windows)

The method I came up was using the embedded printer functions in PHP.  My main web server was linux based, but I setup a separate windows server running IIS and PHP to facilitate direct printing.  The linux server does a server request to the windows server, and passes a query string of information.  The windows server then takes this query string information and uses it to print something directly to a printer.  This method is very stable and was made the primary method for printing from an ERP system for a large warehouse.

Requirements:

  • Windows XP or 2000 web server
  • IIS installed
  • PHP installed
  • Php_printer.dll from PECL extensions (http://pecl.php.net/)

Instructions:

  • Copy the php_printer.dll into the php extensions directory.
  • Edit the php.ini, in the windows extensions section, add the entry “extension=php_printer.dll” after the php_sqlite item
  • Install printers onto the server
  • Install a code39 font if barcodes are desired
  • From this point forward, use the printer functions build into PHP to send print jobs directly to a printer attached to the server. (http://us3.php.net/manual/en/book.printer.php)

Code samples coming soon.

Categories: PHP Tags: , ,