如何直接从打印机打印?
这是一个Intranet Web应用程序。用户将使用此应用程序,他们将从其部门的打印机(不同部门,不同的打印机)打印出报告。我正在谷歌搜索直接从打印机打印,但我找不到任何地方。我正在使用Yii Framework 1.11。
我该怎么做?是否可以直接从打印机打印出来?怎么样?
答案 0 :(得分:0)
你可以试试这个: -
$fhandle = fopen("test.php","rb");
$contents = fread($fhandle, filesize("test.php"));
$output = eval($contents);
$handle = printer_open("Dell Laser Printer M5200");
printer_set_option($handle,PRINTER_MODE,"raw");
printer_write($handle,$output);
printer_close($handle);
答案 1 :(得分:0)
对于Web应用程序,所有打印工作都依赖于您的浏览器。您必须创建一个页面或弹出窗口,仅用于具有特殊Html和CSS的打印视图。
答案 2 :(得分:0)
至少我是最好的方式。我从以下网站获得了js。
http://www.position-absolute.com/articles/printing-web-pages-a-new-jquery-printing-plugin/
我的观点(索引或其他)
<p align="right">
<?php
echo CHtml::link('New Job',array('create'),array('class'=>'btn btn-info'));
echo CHtml::link('Print',array('print'),array('class'=>'btnPrint btn btn-info', 'style'=>'margin-left: 10px;'));
?>
</p>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'job-grid',
'dataProvider'=>$jobs->search(),
'filter'=>$jobs,
...)); ?>
我的控制器
public function actionPrint() {
$d = $_SESSION['all'];
$this->renderPartial('print',array('d'=>$d),false,true);
}
我的模特
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('date',$this->date,true);
$criteria->compare('department_id',$this->department_id);
$criteria->compare('section_id',$this->section_id);
$criteria->compare('team_id',$this->team_id);
$criteria->compare('created_date',$this->created_date,true);
$criteria->compare('updated_date',$this->updated_date,true);
$data = new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'pagination'=>false,
));
$_SESSION['all'] = $data;
$data = new CActiveDataProvider(get_class($this), array(
'pagination'=>array('pageSize'=> Yii::app()->user->getState('pageSize',
Yii::app()->params['defaultPageSize']),),
'criteria'=>$criteria,
));
$_SESSION['limited'] = $data;
return $data;
}
我的观点(print.php)
<div id="summary">
<table width="100%" border="1">
<tr>
<th>No.</th>
<th>Job No.</th>
<th>Date</th>
<th>Department</th>
<th>Section</th>
<th>Team</th>
</tr>
<?php
$i=1;
foreach($d->data as $item)
{
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $item->name; ?></td>
<td><?php echo $item->date; ?></td>
<td><?php echo $item->departmentsdep->name; ?></td>
<td><?php echo $item->departmentssec->name; ?></td>
<td><?php echo $item->departmentstea->name; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</div>