我有一个直接从php打印的问题,我不想使用window.print
,因为这取决于浏览器。所以我用这个代替:直接从php打印
<!DOCTYPE html>
<html>
<body>
<textarea rows="5" cols="50">
<?php
$myfile = fopen("test.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
$file = file_get_contents('./test.txt', FILE_USE_INCLUDE_PATH);
echo $file;
$printer = printer_open("Adobe PDF");
if($ph = printer_open($printer))
{
// Get file contents
$fh = fopen("test.txt", "rb");
$content = fread($fh, filesize("test.txt"));
fclose($fh);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
printer_close($ph);
}
else "Couldn't connect...";
?>
?>
</textarea>
</body>
</html>
我已经添加了php_printer.dll extention,但我得到了下面的错误,而不是:
John Doe
Jane Doe
<br />
<b>Warning</b>: printer_open(): couldn't connect to the printer [Resource id #5] in <b>F:\LOKAL\text\text.php</b> on line <b>15</b><br />
?>
如何处理此问题?谢谢。
你确定这台物理打印机是服务器系统已知的吗?这将是一个有点异国情调的设置,虽然不是不可能的。也许您想尝试使用基于网络的方法,以便将文档发送到支持网络的打印机或打印服务器。例如,有'CUPS'打印系统的扩展。 – arkascha