CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · July 26, 2017

Printing from PHP directly to a PCL printer (Linux)

Posted on Tuesday, November 25, 2014 @ 01:09:37 PM CST by David Yee [] [read 7797 times]
 
PHP Tips and Code Examples


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 is how to do it with PHP:



  1. Output the html to a temporary file, e.g.

    fopen($tmp_file, "w+") or die ("Print error: Can't write file $tmp_file.");

  2. 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"); Of course you would need to have Perl installed


  3. 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


  4. Next, simply use lpr -P$name_of_your_print_queue to print the file - for instance, using the printer name of "my_laserjet":

    exec("lpr -Pmy_laserjet /tmp/form.pcl");


Now this is all assuming that you have already setup the print queue. If any problem arises, try to use the lpr command to print to the printer directly first. When you are all done, close the temporary file:

fclose('/tmp/form.pcl')



Right now there are 2 comments/reviews for Printing from PHP directly to a PCL printer (Linux).
Please rate this article or post a brief review of Printing from PHP directly to a PCL printer (Linux) or comment on benchmark/performance, features, availability, price or anything else regarding Printing from PHP directly to a PCL printer (Linux). Thanks!

Printing From PHP Directly To A PCL Printer (Linux) Rating: 2.6/5 (21 votes cast) 2 comment(s) by users total.

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title:
Comment/Review:

User-Submitted Reviews of Printing from PHP directly to a PCL printer (Linux) & Testimonials

David reviewer photoPosted by David (2½ years ago)

PCL command for duplexing

I think you have to find the specific PCL command codes to do the duplex/specific tray functions. I am not versed in PCL so I can't help you further, but maybe there's some reference out there, e.g.:

support.microsoft.com/kb/194306

The PCL command for duplex appears to be "an ampersand, lower-case L, numeric 1, and upper-case S", like: &l1S

Good luck!

Was this review helpful for you?

  +2

  -0
Reply
Toggle Comment Form









2 out of 2 people said 'YES'

850

Posted by zander (2½ years ago)

Question

This gives me a great start however do you have any suggestions regarding the use of PCL commands to specify how the print job should be handled?

Two examples I have are:

Specifying that a job should be printed in duplex.

Specifying that particular pages should use paper from particular trays.

I just can't find ANY examples of how to do this - maybe because its printer specific?

Was this review helpful for you?

  +0

  -0
Reply
Toggle Comment Form








840