yii2基本打印pdf格式的页面

yii2基本打印pdf格式的页面,yii2,Yii2,请帮忙。 大家好,我即将完成一个使用yii2basic创建的项目。我的问题是,我想打印一个使用pdf作为输出的文件。我尝试过yii2 mpdf和yii2 pdf,但没有成功。我想将打印按钮放在视图文件的index.php中。这是我在索引视图文件中的代码片段 <?= Html::a('<i class="fa glyphicon glyphicon-hand-up"></i>Property report',['/propertydetails/report'],

请帮忙。 大家好,我即将完成一个使用yii2basic创建的项目。我的问题是,我想打印一个使用pdf作为输出的文件。我尝试过yii2 mpdf和yii2 pdf,但没有成功。我想将打印按钮放在视图文件的index.php中。这是我在索引视图文件中的代码片段

<?= Html::a('<i class="fa glyphicon glyphicon-hand-up"></i>Property report',['/propertydetails/report'],
        [
         'class'=>'btn btn-danger',
         'target'=> '_blank',
         'data-toggle'=>'tooltip',
         'title'=>'Generate the pdf']); ?> 
当我点击按钮时,我得到了这个错误

 PHP Notice – yii\base\ErrorException
未定义变量:模型

1. in C:\wamp\www\pakiSystems1\views\propertydetails\view.php at line 9
123456789101112131415161718

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\Propertydetails */

$this->title = $model->propertyId;
$this->params['breadcrumbs'][] = ['label' => 'Propertydetails', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="propertydetails-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Update', ['update', 'id' => $model->propertyId], ['class' => 'btn btn-primary']) ?>

2. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderPhpFile() at line 247
3. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderFile() at line 149
4. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\Controller.php – yii\base\View::render() at line 398
5. in C:\wamp\www\pakiSystems1\controllers\PropertydetailsController.php – yii\base\Controller::renderPartial() at line 77
71727374757677787980818283

    public function actionReport()
    {
        //get your html raw content without layouts
       // $content = $this->renderPartial('view');
        //set up the kartik\mpdf\Pdf component
        $pdf = new Pdf([
            'content'=>$this->renderPartial('view'),
            'mode'=> Pdf::MODE_CORE,
            'format'=> Pdf::FORMAT_A4,
            'orientation'=>Pdf::ORIENT_POTRAIT,
            'destination'=> Pdf::DEST_BROWSER,
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            'cssInline'=> '.kv-heading-1{font-size:18px}',
1。在C:\wamp\www\pakiSystems1\views\propertydeails\view.php的第9行
123456789101112131415161718

2.在第247行的C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php–yii\base\View::renderppfile()中
3.在C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php–yii\base\View::renderFile()的第149行
4.在第398行的C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\Controller.php–yii\base\View::render()中
5.在C:\wamp\www\pakiSystems1\controllers\propertydetailscocontroller.php–yii\base\Controller::renderPartial()中的第77行
71727374757677787980818283
公共职能行动报告()
{
//获取没有布局的html原始内容
//$content=$this->renderPartial('view');
//设置kartik\mpdf\Pdf组件
$pdf=新pdf([
'content'=>$this->renderPartial('view'),
'mode'=>Pdf::mode_CORE,
'format'=>Pdf::format_A4,
“方向”=>Pdf::ORIENT_POTRAIT,
“目的地”=>Pdf::目的地浏览器,
“cssFile'=>”@vendor/kartik-v/yii2 mpdf/assets/kv mpdf bootstrap.min.css',
'cssInline'=>'.kv-heading-1{font size:18px}',

任何帮助我都将不胜感激。提前谢谢您的控制器中没有型号。 您必须添加此信息,例如:

$content = $this->renderPartial('_mpdf_report_scheda',  [
     'model' => $model,

     'mode'=> Pdf::MODE_CORE,
     'format'=> Pdf::FORMAT_A4,
     'orientation'=>Pdf::ORIENT_POTRAIT,
     'destination'=> Pdf::DEST_BROWSER,
     .....
           ]);

成功了。:)非常感谢。我真的很感激。如果我可以问为什么Pdf::ORIENT_POTRAIT不起作用?在《我不知道该怎么做》中。我邀请你在StackOverflow中提出另一个问题。这样,更多的人可以看到你的问题并可以帮助你。新问题比旧问题读得更多。还有一个小问题。当它转换为Pdf时,它是not已转换但在renderPartial中的当前页面('index','searchModel'=>$searchModel)。如何打印当前显示的页面??再次感谢您的时间页面中使用的数据在调用renderPartial时转换为PDF格式。如果您需要实际页面的数据(我猜您调用PDF打印时看到的页面)您必须在$model处分配正确的数据实例..好的。现在我无法使用正确的实例。
$content = $this->renderPartial('_mpdf_report_scheda',  [
     'model' => $model,

     'mode'=> Pdf::MODE_CORE,
     'format'=> Pdf::FORMAT_A4,
     'orientation'=>Pdf::ORIENT_POTRAIT,
     'destination'=> Pdf::DEST_BROWSER,
     .....
           ]);