简体   繁体   English

如何使用帮助PHP打印文件

[英]How to print out file with help PHP

Is there any way to print out (to cups for example) html file with help PHP (linux server without X) ? 有什么方法可以通过帮助PHP(不带X的Linux服务器)来打印(例如到杯子)html文件?

except shell_exec(), system() etc... 除了shell_exec(),system()等...

And when i mean print html file means print not source code, means print rendered result. 当我的意思是打印html文件意味着打印非源代码时,意味着打印渲染结果。 is it possible with help PHP ? 有可能通过PHP帮助吗?

I know thath there is some possibilities like, - run X server, - run browser, - exec terminal command which will ask browser open and print out html file 我知道有一些可能性,例如-运行X服务器,-运行浏览器,-exec终端命令,将要求浏览器打开并打印出html文件。

but without shell_exec is it possible ? 但是没有shell_exec是可能的吗?

You'll need to render the file yourself into some sort of printable format such as a postscript or PDF file. 您需要自己将文件呈现为某种可打印的格式,例如Postscript或PDF文件。 There is a good PHP5 library to create PDFs from HTML called dompdf . 有一个很好的PHP5库,可以从HTML创建pdf,称为dompdf

So generate the HTML output and store it into a string, you may want to use output buffering to do this. 因此,生成HTML输出并将其存储到字符串中,您可能需要使用输出缓冲来执行此操作。 See the PHP manual . 参见PHP手册

Then you can use dompdf to render the HTML contents into a PDF file. 然后,您可以使用dompdf将HTML内容呈现为PDF文件。 Storing it into a temp directory probably makes sense if you don't need to keep the file. 如果不需要保留文件,则将其存储到临时目录中可能很有意义。

Then, you can use the cups cli to print the file, see the cups documentation . 然后,您可以使用cups cli打印文件,请参阅cups文档 eg 例如

shell_exec('lp '.$filename);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM