2016-5-9 Frank
"require": {
"yiisoft/yii2-swiftmailer": "*",
"kartik-v/yii2-mpdf": "dev-master"
},
php composer.phar install
$content = "这是邮件内容" ;
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => '你好,世界',
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
'cssInline' => '.kv-heading-1{font-size:24px}',
// set mPDF properties on the fly
'options' => [
'title' => 'VOUCHER',
'autoLangToFont' => true, //这几个配置加上可以显示中文
'autoScriptToLang' => true, //这几个配置加上可以显示中文
'autoVietnamese' => true, //这几个配置加上可以显示中文
'autoArabic' => true, //这几个配置加上可以显示中文
],
// call mPDF methods on the fly
'methods' => [
'SetHeader' => ['VOUCHER'],
'SetFooter' => ['{PAGENO}'],
]
]);
$pdf_as_string = $pdf->Output($content, '', 'S'); //这里是关键哦
$mailer = Yii::$app->mailer->compose('html', []);
$mailer->setFrom(["frank@liangcuntu.com" => "两寸土"]);
$mailer->setTo("frank@liangcuntu.com");
$mailer->setSubject("title");
$mailer->attachContent($pdf_as_string, ["fileName" => "test.pdf", "contentType" => "application/pdf"]);
$mailer->send();
参考:
https://github.com/yiisoft/yii2-swiftmailer
https://github.com/kartik-v/yii2-mpdf
评论:
发表评论 登录:
2016-05-09 19:58
'autoLangToFont' => true, //这几个配置加上可以显示中文
'autoScriptToLang' => true, //这几个配置加上可以显示中文
'autoVietnamese' => true, //这几个配置加上可以显示中文
'autoArabic' => true, //这几个配置加上可以显示中文
]);