2016-12-09 10:54:51 0 评论 Yii 2.0 Boy.Lee

Yii 2.0中使用mPDF 生成中文pdf文件

{ update config }

//open /mPDF/config.php
$this->autoLangToFont = true; // mPDF 6.0 (similar to old useLang)

 

{ Demo Code }

require dirname ( dirname ( __DIR__ ) ).'/vendor/mpdf/vendor/autoload.php';

$mpdf = new \mPDF(
        'utf-8',    // mode - default ''
        'A4-L',  // format - A4, for example, default ''
         0,     // font size - default 0
         '',    // default font family
         10,    // margin_left
         10,    // margin right
         10,     // margin top
         0,    // margin bottom
         9,     // margin header
         9     // margin footer
        );
$mpdf->autoScriptToLang = true;

// add html to pdf
$mpdf->WriteHTML("大家好这里是YiiLib.com");

// Output the generated PDF to Browser
$mpdf->Output();

//save pdf as yiilib.pdf
$mpdf->Output('/var/tmp/yiilib.pdf');