我有centos 5与php 5.2.4。我有一个文件,html,我想打印。我如何在linux上做到这一点。我似乎找不到任何关于它的东西。都是Windows的东西。我想用客户的打印机打印。我尝试了以下哪些错误。
$handle = printer_open();
printer_write($handle, "Text to print");
printer_close($handle);
[Wed May 22 08:00:27 2013] [error] [client 172.16.0.85] PHP Fatal error: Call to undefined function printer_open() in /opt/invload/protected/controllers/SiteController.php on line 485, referer: http://portal-dev/invload/index.php?r=site/report&view=report
我正在使用Yii框架,我正在查看打印的页面是分页的。做window.print
不会打印所有结果,所以我做了一个jquery,可以查询所有结果并输出到文件。现在我要打印这个文件
in my view
<?php
$this->pageTitle=Yii::app()->name . ' - Reports';
?>
<style type="text/css">
.odd {
background: none repeat scroll 0 0 #E5F1F4;
}
.even {
background: none repeat scroll 0 0 #F8F8F8;
}
table tbody tr:hover{
background: none repeat scroll 0 0 lightgreen;
}
table tbody tr{
font-size:10pt;
}
body
{
margin: 0mm 0mm 0mm 0mm;
}
</style>
<body onload="window.print();window.close();">
<table>
<tr>
<th>No_</th>
<th>Pay-to Name</th>
<th>Order No</th>
<th width="50px">Vendor Invoice No</th>
<th>Log Number</th>
<th width="65px">Posting Date</th>
</tr>
<?php
$count = 0;
$class= null;
foreach($dataProviderAll->getData() as $q) {
$class = ($count % 2 === 0) ? 'odd' : 'even';
$this->renderPartial('_report',array('data'=>$q,'class'=>$class));
$count++;
}
?>
</table>
</body>
in my controller
public function actionPrint(){
$company = Yii::app()->params['currentCompany'];
$query = Yii::app()->dbNav->createCommand("SELECT [No_] AS [no],[Pay-to Name] AS [paytoname],[Order No_] AS [orderno],[Vendor Invoice No_] AS [vendorinvoiceno], [Log Number] AS [lognumber],[Posting Date] AS [postingdate]
FROM [$company'$Purch_ Inv_ Header] WHERE [Log Number] is not null and [Log Number] not in (
SELECT [InvoiceLogNo] FROM [$company'$Invoice Image Locations])
ORDER BY " . $this->order . " " . Yii::app()->session['asc_or_desc'])->queryAll();
//print_r(count($query));
$dataProviderAll = new CArrayDataProvider($query);
$item_count = count($query);
$pages = new CPagination($item_count);
$pages->setPageSize($item_count);
$dataProviderAll->setPagination($pages);
$print = $this->renderPartial('print',array('dataProviderAll'=>$dataProviderAll),true);
//print_r($print);
$file = "/tmp/reports.html";
file_put_contents($file, $print);
header("Content-disposition: attachment;filename=$file");
readfile($file);
}
你正在谈论客户端打印,因此你需要使用客户端技术,即Javascript。
你可以调用window.print()来打印活动窗口。检查:http://www.w3schools.com/jsref/met_win_print.asp
如果你想控制打印内容(例如设置横向/纵向打印),你可以使用浏览器插件。对于Firefox,你可以使用jsprintsetup:https://addons.mozilla.org/en-us/firefox/addon/js-print-setup/
Edit:更新后,问题中增加了更多信息。在下面添加额外的回复
在本例中,您可以在一个新页面中打开包含合并结果的页面并打印它。或者,您也可以将所有结果输出到一个不可见的制表符中,并打印其内容
Edit2(回复下面的评论):要用你的数据打开一个新窗口,你可以在javascript中使用window.open():
window.open("site.com/something.php?param1=1¶m2=2");
,然后在该窗口内执行:
window.print();
window.close();
查看更多信息:
- http://www.w3schools.com/jsref/met_win_open.asp
- http://www.w3schools.com/jsref/met_win_print.asp
- http://www.w3schools.com/jsref/met_win_close.asp
$("<iframe id='"printFrame'" src='"" + yourURL + '" width='"0'" height='"0'" frameborder='"0'" scrolling='"no'"/>").insertAfter($('body'));
将创建一个0x0 iframe,其中包含您想要的页面内容。然后,该页面可以使用window.print();