PHP 5中的服务器端打印

时间:2012-05-30 05:35:58

标签: php html printing server-side

如何通过php脚本打印我的html文件?我只是想在没有任何提示的情况下在后台运行它。我已经阅读了有关此内容的其他帖子,但仍未发现任何有用的信息。 我试过这个:

<?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");
?>

在这里得到了这个例子http://www.phpfreaks.com/forums/index.php/topic,207946.0.html

3 个答案:

答案 0 :(得分:3)

这就是我的工作:

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

我们需要 php_printer.dll php扩展才能在php5中运行。 :)

答案 1 :(得分:2)

您无法使用php打印html页面。 Php是一种服务器端语言,它在服务器上运行。

打印机在客户端的计算机上。这意味着你需要一个客户端语言才能实现这一目标。

答案 2 :(得分:0)

如果要打印源代码,那么应该通过编写打印传递的字符串然后通过系统调用调用它的程序来实现。在Windows上,它似乎有一个扩展名。

如果要打印渲染版本,那么你必须知道为此你需要某种渲染引擎。虽然并非不可能,但它可能比你想进入的工作更多。