2

如何直接从打印机打印?

这是一个 Intranet Web 应用程序。用户将使用此应用程序,他们将从其部门的打印机(不同部门,不同的打印机)打印出报告。我正在谷歌搜索直接从打印机打印出来,但我找不到任何地方。我正在使用 Yii 框架 1.11。

我怎样才能做到这一点?可以直接从打印机打印出来吗?如何?

4

3 回答 3

0

对于 Web 应用程序,所有打印作品都依赖于您的浏览器。您必须为具有特殊 Html 和 css 的打印视图创建一个页面或弹出窗口。

于 2012-12-21T12:43:16.770 回答
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>
于 2012-12-24T09:19:35.720 回答
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);
于 2012-12-21T10:42:45.417 回答