使用PHP将数据打印到打印机 [英] Printing data to printer using PHP

查看:527
本文介绍了使用PHP将数据打印到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题困扰了我至少三个星期.我需要使用php将一些数据打印到打印机.我已将数据保存到$print_output变量中,并且我知道我的数据很好,因为当我通过电子邮件发送数据时,它会显示应该显示的所有内容.

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); 

好吧,事实证明我没有安装php_printer.dll扩展名,并且被告知不要重新编译php来添加它.

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

我想做的只是将存储在$print_output中的数据打印到同一网络上的打印机.我不想使用JavaScript函数window.print(),因为我无法弹出打印对话框屏幕.

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.

有人可以向我指出正确的方向吗?还是不使用php的printer_open函数直接将少量数据直接直接打印到打印机的另一种方法?

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?

推荐答案

对于遇到同样麻烦的任何人,我都知道我可以使用套接字编程按如下方式简单地推送数据.下面的IP地址是我的打印机的IP地址.如果需要,您可以通过telnet进入打印机以确保连接能够正常工作.

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

这篇关于使用PHP将数据打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆