使用 PHP 将数据打印到打印机

Printing data to printer using PHP(使用 PHP 将数据打印到打印机)
本文介绍了使用 PHP 将数据打印到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个问题困扰了我至少 3 周.我需要使用 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(), "
";
}

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)