我正在从事一个打印学生收据的项目。
public function actionPrintCommonReceipt($sid, $fcid)
{
$model = new FeesPaymentTransaction();
$stuData = \app\modules\student\models\StuMaster::findOne($sid);
$FccModel = \app\modules\fees\models\FeesCollectCategory::findOne($fcid);
$title = Yii::t('fees', "Receipt of ").$stuData->stuMasterStuInfo->name.' : '.Yii::$app->dateformatter->getDateDisplay(date('Y-m-d'));
$html = $this->renderPartial('print-common-receipt', [
'model' => $model,
'stuData' => $stuData,
'FccModel'=> $FccModel,
'title'=>$title,
]);
$imgSrc = Yii::$app->urlManager->createAbsoluteUrl('site/loadimage');
$mpdf = new mPDF('utf-8', 'A4',0,'',15,15,25,16,4,9,'P');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML('<watermarkimage src='.$imgSrc.' alpha="0.33" size="50,30"/>');
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($html);
$mpdf->Output($title.'.pdf', "I");
}
查看
<div class="box-footer">
<div class="<?= (Yii::$app->language == 'ar') ? 'pull-left' : 'pull-right'; ?>" style="padding-bottom:10px">
<?php if($collectOn) { echo Html::submitButton($model->isNewRecord ? '<i class="fa fa-plus-circle"></i> '.Yii::t('fees', ' Take Fees') : '<i class="fa fa-pencil-square-o"></i> '.Yii::t('fees', 'Update Fees'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-info']); } ?>
<?php if($printOn & $model->isNewRecord) { echo Html::a('<i class="fa fa-print"></i> '.Yii::t('fees', 'Print receipt'),['print-common-receipt', 'sid'=>$stuData->stu_master_id, 'fcid'=>$FccModel->fees_collect_category_id], ['class' => 'btn btn-warning', 'target'=>'_blank']); } ?>
<?php if(!$model->isNewRecord) { echo Html::a(Yii::t('fees', 'Cancel'),['pay-fees', 'sid'=>$stuData->stu_master_id, 'fcid'=>$FccModel->fees_collect_category_id], ['class' => 'btn btn-default']); } ?>
</div>
</div>
从上面的视图中,单击“打印回执”按钮,它将在屏幕上显示PDF回执。
但是我不希望那样。我希望在单击“打印”按钮后立即将收据直接发送到打印机。我该如何实现。我正在使用mPDF