initiating a remote printing job of a URL on a Linux system

Hi guys,

I have a web application (PHP / MySQL) running on a remote Debian Linux server.  Essentially, I'm looking for recommendations on how I can have the server load a URL locally (PHP file) parse it correctly (including CSS) and print the output of the PHP file to a local printer.

I'm trying to avoid having to generate a PDF file locally and print that each time if possible.

Something involving shell_exec would work.

Is there any program that I could use from the command line that could load a URL (need to pass GET variables) and then print the result to a printer?  I have the printer already set up in CUPS.  Neither Links or Lynx see to understand CSS.

Thanks guys.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Syngin9,

I believe you can do this by create a PHP communication link between one server and the other. On your Linux server once some has complete the request have your PHP script open a link to your second computer:

$values = 'this is what I want to print';
$message = file_get_contents('' . $values);

Once your second server has read all the values you can issue a command to print the contents to the print. This can be done through PHP:

Read Values:

$values = $_REQUEST['values'];

Print to Printer:

$printer = "link_to_printer");
if($ph = printer_open($printer))
   printer_set_option($ph, PRINTER_MODE, "RAW");
   printer_write($ph, $values);

Once the document has printed you can tell your first server that you are done by:

return 'done';

Hope the above helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Syngin9Author Commented:
Ok thanks. Actually, I wasn't aware of the PHP printer options.  There wouldn't be 2 servers though, just someone accessing the app on the server via a browser on one system.  One they hit a certain point in the app, the server would print a work order with information from the database on the server's local network (Lets say the printer is named Printer_1 in CUPS and its located at

2 questions:

1. How would you define the link to the printer?  I have the printer set up in CUPS on the server but I'm unsure how to call it.  Would it be via IP or do I somehow reference the name I gave it in CUPS?

2. Would this print out the HTML code that is generated or the result of the HTML code?

Thanks again for your help.
Question 1:

You should be able to access the printer via the name "Printer_1" if that doesn't work, I would enable the printer for the network and try "\\\\localhost\\Printer_1".

Question 2:

With the printer mode to "RAW" it will print out the HTML code as the mode takes a STRING as a value. You can use a simple PHP PDF writer to the style you are looking for. After searching in the internet I found the following method useful for print PDF, DOC, etc. files. Of course it needs to be adjust as it is written for a windows machine.

Courtesy of Darren's Script Archive:


function print_file($filename)
    // path to your adobe executable
    $adobe_path='"C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32.exe"';


    if ($ext=='pdf') {
        shell_exec ($adobe_path.' /t '.$filename);
    else if ($ext=='doc'||$ext=='rtf'||$ext=='txt') {
        $word = new COM("Word.Application");
        $word->visible = true;
    else if ($ext_xl=='xl') {
        $excel = new COM("Excel.Application");
        $excel->visible = true;

// example of printing a PDF



Open in new window

Syngin9Author Commented:
Awesome, I will give that a try.

On a side note, I get a call to undefined function when I try to execute printer_open.  I had a look through phpinfo() but don't see anything in there regarding printing, same with php.ini.  Any thoughts on how I can get this function enabled?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.