• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

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.

0
Syngin9
Asked:
Syngin9
  • 2
  • 2
1 Solution
 
nbandanCommented:
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('http://example.com/processor/query.php?ref=' . $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);
   printer_close($ph);
}

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

return 'done';

Hope the above helps.
0
 
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 192.168.6.30).

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.
0
 
nbandanCommented:
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: http://www.tufat.com

<?php

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

    $ext='';
    $ext=strrchr($filename,'.');
    $ext=substr($ext,1);
    $ext_xl=substr($ext,0,2);

    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;
        $word->Documents->Open($filename);
        $word->ActiveDocument->PrintOut();
        $word->ActiveDocument->Close();
        $word->Quit();
    }
    else if ($ext_xl=='xl') {
        $excel = new COM("Excel.Application");
        $excel->visible = true;
        $excel->Workbooks->Open($filename);
        $excel->ActiveWorkBook->PrintOut();
        $excel->ActiveWorkBook->Close();
        $excel->Quit();
    }
}

// example of printing a PDF

print_file("C:/photo_gallery.pdf");

?>

Open in new window

0
 
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now