gpt4 book ai didi

php - 如何使用php 5.2.4将文件发送到centos上的打印机

转载 作者:行者123 更新时间:2023-12-04 19:38:42 25 4
gpt4 key购买 nike

我有 php 5.2.4 的 centos 5。我有一个文件,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。现在我想打印那个文件。

在我看来
<?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>

在我的 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/

编辑 : 更新后,问题中添加了更多信息。在下面添加其他回复。

在这种情况下,您可以在新页面中打开包含组合结果的页面并打印。或者,您可以在不可见的选项卡中输出所有结果并打印其内容

编辑2 (回复下面的评论):
要使用您的数据打开一个新窗口,您可以使用 window.open() 从 javascript 执行此操作:

window.open("site.com/something.php?param1=1&param2=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,而不是新窗口。唯一的区别是您不会调用 window.open(),但会在页面上打印一个新的 iframe。例如,使用 jQuery,您可以执行以下操作:
    $("<iframe id=\"printFrame\" src=\"" + yourURL + \" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"/>").insertAfter($('body'));

    这将创建一个包含您想要的页面内容的 0x0 iframe。然后该页面可以使用 window.print() 打印自己;

    关于php - 如何使用php 5.2.4将文件发送到centos上的打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16688337/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com