问题描述
在php中使用 printer_open()
函数,我可以打印保存在 $ content
变量,并能够从文件打印。
$ printer =\\\\Pserver.php。 net\\printername;
$ handler = printer_open($ printer);
$ content =测试内容; //字符串
printer_write($ handler,$ content);
printer_close($ handler);
但是我有一个从数据库生成的html输出,并且显示在网页中,我需要直接打印到相同的格式,一旦页面加载,我试了很多,但我不知道我应该怎么做,使打印机直接打印相同的HTML输出一旦页面加载使用 printer_open()
。
我应该怎么做?如果有的话,请建议一个更好的方法
更新
我不想使用javascript的windows.print()方法,因为它显示的是打印对话框,而不是直接启动打印作业到打印机。
我希望用户点击提交表单和打印机直接打印收据而不询问任何内容
您可以尝试使用输出缓冲区:
ob_start();
//在这里从DB生成输出
// .....
//将生成的输出发送到打印机
printer_write($ handler,ob_get_contents ());
//在前台显示给客户
ob_end_flush();
With printer_open()
function in php, I am able to print the string that I saved in $content
variable, and able to print from a file.
$printer = "\\\\Pserver.php.net\\printername";
$handler = printer_open($printer);
$content = "Test Content"; //string
printer_write($handler, $content);
printer_close($handler);
But have a html output that I generated from the database, and is showing in the webpage, I need to print that directly to the printed in the same format once the page loads, I tried a lot but I dont know what I should do to make the printer to print directly the same HTML output once the page loads using the printer_open()
.
What should I do? Please suggest a better method than this if any
UPDATED
I dont want to use windows.print() method of javascript, since it shows the print dialogue box instead of initiating the printing job directly to the printer
I want users to hit submit form and printer to print the receipt directly without asking them anything
You can try to use output buffer:
ob_start();
// generate your output from the DB here
// .....
// Send generated output to the printer
printer_write($handler, ob_get_contents());
// And show it to client on the frontend
ob_end_flush();
这篇关于Printer_open()打印html输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!