Printing data to printer using PHP

user3150191

I have a question that has been troubling me for at least 3 weeks now. I need to print some data to a printer using php. I have data saved into a $print_output variable, and I know my data is good because when I send it via email, it shows everything that is supposed to be shown.

Well, I tried writing this code, where I thought I could test it but wasn't sure if it would have even worked.

$handle = printer_open("\\\\192.168.1.33_4\\Printer_Office");
printer_set_option($handle, PRINTER_MODE, "raw"); 
printer_write($handle,$print_output); 
printer_close($handle); 

Well, turns out I don't have php_printer.dll extension installed and I was told not to re-compile php to add it.

What I'd like to do is simply print out the data that is stored in $print_output to a printer on my same network. I don't want to use the javascript function window.print() because I can't have a print dialogue screen pop up.

Does anyone have any information that can point me in the right direction? Or another way to simply print a small amount of data directly to the printer without using php's printer_open function?

user3150191

For anyone who is having the same trouble, I figured out I can simply push the data using socket programming as follows. The ip address below is my printer's ip address. You can telnet into your printer to make sure the connection works beforehand if you'd like.

if(isset($_POST['order'])){
$print_output= $_POST['order'];
}
try
{
    $fp=pfsockopen("192.168.1.33", 9100);
    fputs($fp, $print_output);
    fclose($fp);

    echo 'Successfully Printed';
}
catch (Exception $e) 
{
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related