2013-05-22 26 views
0

我有php 5.2.4的centos 5。我有一個文件,html,我想打印。我怎麼能在Linux上做到這一點。我似乎無法找到任何關於它的任何地方。它只是所有的窗口的東西。我想用客戶打印機打印。我試過以下哪個錯誤。如何發送文件到打印機上使用php的centos 5.2.4

$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> 

在我的控制器

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);  
} 
+0

你的意思是服務器端的打印機?使用瀏覽器 –

+0

客戶端打印機 – shorif2000

回答

1

你是在談論客戶端打印,所以你需要使用客戶端技術,即使用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/

編輯:更新後的詳細信息,已被添加到這個問題。在下面添加更多回復。

在這種情況下,您可以在一個新頁面中打開包含組合結果的頁面並打印出來。或者,你可以輸出一個無形的標籤的所有結果,並打印其內容

EDIT2(回覆到下面的評論): 要與您的數據打開一個新窗口,你可以使用JavaScript做window.open():

window.open("site.com/something.php?param1=1&param2=2"); 

,然後從該窗口中,執行:

window.print(); 
window.close(); 

欲瞭解更多信息:

同樣,您可以使用此一種無形的iframe,而不是一個新的窗口。唯一的區別是你不會調用window.open(),但是你會在頁面上打印一個新的iframe。例如,使用jQuery你可以這樣做:

$("<iframe id=\"printFrame\" src=\"" + yourURL + \" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"/>").insertAfter($('body')); 

這將創建一個帶有所需頁面內容的0x0 iframe。然後該頁面可以使用window.print()打印自己。

+0

更新的問題 – shorif2000

+0

增加了額外的信息,以我的回覆,更改後 –

+0

我已經更新了我的代碼輸出文件內容,並允許用戶將其打開。如何更改我的代碼以便在沒有用戶干預的情況下打印和關閉? – shorif2000

相關問題