Printing data to printer using PHP

后端 未结 2 643
日久生厌
日久生厌 2020-12-25 08:56

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

2条回答
  •  清歌不尽
    2020-12-25 10:00

    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";
    }
    

提交回复
热议问题