Server side printing in PHP 5

不想你离开。 提交于 2019-12-25 01:33:13

问题


How can i print my html file via php script? I just want to run it in background without any prompt. I have read other posts regarding this but still didnt find anything working. I tried this one :

<?php
$dir = "temp"; // the folder that you are storing the file to be printed
$file = "file.html"; //change to proper file name
$file_dir = $dir.$file;
$server = "home_computer"; //name of the computer you are printing to on your network
$printer = "HP"; //printers shared name
$command = "print $file_dir /d:\\$server\\$printer";
exec($command) or die("File failed to print");
?>

got this example here http://www.phpfreaks.com/forums/index.php/topic,207946.0.html


回答1:


here is what i got working :

$html = "testing print";
$handle = printer_open();
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, $html);
printer_close($handle);

We require php_printer.dll php extension to make this work in php5. :)




回答2:


You can't print html pages with php. Php is a server-side language, it runs on the server.

The printer is on the client's machine. Meaning you'll need a client-side language to accomplish this.




回答3:


If you want to print the source code then it should be be doable by writing a program that prints the passed string and then calling it via a system call. On windows it appears to have an extension for that.

If you want to print a rendered version, then you have to know that for that you need some kind of a rendering engine. While not impossible its probably more work than what you want to get into.



来源:https://stackoverflow.com/questions/10810521/server-side-printing-in-php-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!