yii2 basic 以 pdf 格式打印页面 [英] yii2 basic printing a page in pdf

查看:21
本文介绍了yii2 basic 以 pdf 格式打印页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

please help. Hallo all, Am on verge of finishing a project created using yii2 basic. my problem is, I want to print a using with pdf as its output. I have tried yii2 mpdf and yii2-pdf without any success. I want to place the print button in the index.php of a view file. here's is my code snippet located at index view file.

<?= 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']); ?> 

这是我的控制器

use kartik\mpdf\Pdf;

//function for reports
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}',
        'options'=> ['title'=> 'Paki Properties Reports'],
        'methods'=> [
               'setHeader'=>['Generated on: '.date("r")],
               'setFooter'=>['|page {PAGENO}|'],
                ]
        ]);
    return $pdf->render();
}

当我点击按钮时出现此错误

when I click the button I get this error

 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}',

我将非常感谢任何帮助.提前致谢

any help I will highly appreciate. Thanks in advance

推荐答案

在你的控制器中没有模型.您必须添加此信息,例如:

In your controller there isn't the model. You must add this information eg:

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

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

这篇关于yii2 basic 以 pdf 格式打印页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆