php 如何将外部文件的内容发送到打印机?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5627035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send the content of an external file to printer?
提问by Jugal Patel
I want to print (printer, not screen) the content of a file via a PHP script.
我想通过 PHP 脚本打印(打印机,而不是屏幕)文件的内容。
How do I do this?
我该怎么做呢?
回答by rockerest
Update
更新
php cannot easily access hardware. This is generally not considered "possible."
php 无法轻松访问硬件。这通常不被认为是“可能的”。
See:
看:
However, as the first link shows, this is usually done with Javascript. You can output Javascript in a way similar to the methods shown on the first link to force the browser to show the print dialog box.
但是,如第一个链接所示,这通常是使用 Javascript 完成的。您可以以类似于第一个链接中显示的方法的方式输出 Javascript,以强制浏览器显示打印对话框。
Original
原来的
You can use file_get_contentsto print files into a variable or to the output stream.
您可以使用file_get_contents将文件打印到变量或输出流中。
$filecontents = file_get_contents("myfilename.txt");
print $filecontents;
You can also includefiles into your PHP interpretation.
回答by Blindy
A quick and dirty way to print on the client's computer is something like:
在客户端的计算机上打印的一种快速而肮脏的方式是这样的:
print file_get_contents("file.ext");
print "<script>window.print()</script>";
回答by mario
This is certainly not what your question intended, but on any Linux server with a connected printer you could use following:
这当然不是您的问题的意图,但是在任何带有连接打印机的 Linux 服务器上,您可以使用以下内容:
exec("lp file.pdf"); // send file to printer spooler
回答by caglaror
回答by k to the z
// to open a local file use this
$file_handler = fopen("data.txt", "r");
// read the contents
$contents = fread($file_handler, filesize($file));
// close the file
fclose($file_handler);
// print the contents on your page
echo $contents;