Welcome to PHP4IT
Main Menu
· Main Page
· Account Settings
· Forum
· Recommend Us
· Contact


Search


Solutions Categories
· All topics
· Database Import and Conversion with PHP (Feb 07, 2006)
· PHP Security (Mar 28, 2008)
· Printing (Jan 05, 2006)
· Windows PHP Solutions (Apr 04, 2008)


PHP4IT RSS Feed
Add the PHP4IT RSS Feed to your favorite RSS news reader!

  

Printing



See all

Printing a form directly to a PCL printer (Linux)

Posted by: david on Thursday, January 05, 2006 - 06:17 PM
Php Printing 

Let's say that you've built a web application with neat html tables & forms, and you want your users to be able to click on a button and send the page directly to a PCL printer from your app. Or you want the web application to automatically print the html form to a PCL printer. Here's how to do it with PHP:

  • Output the html to a temporary file, e.g. fopen($tmp_file, "w+") or die ("Print error: Can't write file $tmp_file.");
  • convert the html file into a postscript file using the perl command line utility "html2ps" (download html2ps) - e.g. exec("html2ps /tmp/form.html > /tmp/form.ps");
  • convert the postscript file to PC using ghostscript, e.g. exec("gs -sDEVICE=laserjet -sPAPERSIZE=letter -sOutputFile=/tmp/form.pcl -dNOPAUSE -q /tmp/form.ps -c quit"); In this case you are converting the file form.ps into form.pcl
  • simply use lpr -P$name_of_your_print_queue to print the file - e.g. exec("lpr -Pmy_laserjet /tmp/form.pcl"); Now this is assuming that you've already have the print queue setup - voila!

  • Discuss/Submit Comment 2 Reviews/Comments | Email This