iutbay / yii2-mpdf
此包的最新版本(0.2)没有可用的许可证信息。
Yii2 的 mPDF 响应格式化器
0.2
2016-01-29 15:08 UTC
Requires
- mpdf/mpdf: >=6.0.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 18:26:02 UTC
README
为 Yii2 提供的 mPDF 响应格式化器。
https://packagist.org.cn/packages/iutbay/yii2-mpdf
安装
安装此响应格式化器的首选方式是通过 composer。
运行以下命令之一:
composer require "iutbay/yii2-mpdf" "*"
或者
"iutbay/yii2-mpdf" : "*"
将以下内容添加到应用程序的 composer.json
文件的 require 部分:
配置
在应用程序配置的 components 部分添加以下行
'response' => [ 'formatters' => [ 'mpdf' => [ 'class' => 'iutbay\yii2mpdf\MPDFResponseFormatter', // mPDF constructor options : http://mpdf1.com/manual/index.php?tid=184 //'mPDFConstructorOptions' => [ //'mode' => '', //'format' => 'A4', //'defaultFontSize' => '', //'defaultFont' => '', //'marginLeft' => 15, //'marginRight' => 15, //'marginTop' => 16, //'marginBottom' => 16, //'marginHeader' => 9, //'marginFooter' => 9, //'orientation' => 'P', //], // mPDF options : http://mpdf1.com/manual/index.php?tid=273 //'mPDFOptions' => [], // css file path aliases, e.g. ['@app/web/css/pdf.css'] //'cssFiles' => [], // page header : http://mpdf1.com/manual/index.php?tid=149 //'header' => null, // page footer : http://mpdf1.com/manual/index.php?tid=151 //'footer' => null, // ouput options : http://mpdf1.com/manual/index.php?tid=125 //'outputName' => '', //'outputDest' => 'I', ], ], ],
在控制器中使用
示例 1
public function actionPdf() { Yii::$app->response->format = 'mpdf'; return $this->render('pdf'); }
示例 2
public function actionPdf() { Yii::$app->response->format = 'mpdf'; return [ // mPDF construtor options : http://mpdf1.com/manual/index.php?tid=184 //'mPDFConstructorOptions' => [], // mPDF options : http://mpdf1.com/manual/index.php?tid=273 //'mPDFOptions' => [], 'content' => $this->render('pdf'), //'options' => [ // page header : http://mpdf1.com/manual/index.php?tid=149 //'header' => 'Left|Center|Right', // page footer : http://mpdf1.com/manual/index.php?tid=151 //'footer' => 'Left|Center|{PAGENO}/{nbpg}', // ouput options : http://mpdf1.com/manual/index.php?tid=125 //'outputName' => 'test.pdf', //'outputDest' => 'D', //], ] }