Yii2 mpdf更改下载的文件名
Posted
技术标签:
【中文标题】Yii2 mpdf更改下载的文件名【英文标题】:Yii2 mpdf change downloaded filename 【发布时间】:2017-08-03 04:14:14 【问题描述】:我正在处理 SiteController 动作打印,这是我的代码
$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_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
'marginTop' => 5,
'marginLeft' => 5,
// your html content input
'content' => $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-1font-size:18px',
// set mPDF properties on the fly
'options' => ['title' => 'Customer Invoice'],
// call mPDF methods on the fly
'methods' => [
// 'SetHeader'=>['Krajee Report Header'],
// 'SetFooter'=>['PAGENO'],
]
]);
// return the pdf output as per the destination setting
return $pdf->render();
触发此操作时,它会在浏览器上呈现 pdf,但是当我单击下载按钮时,默认文件名是“打印”。怎么改?
请帮忙!!!
【问题讨论】:
Changing the default filename when using mPDF的可能重复 我可以知道这个脚本'options' => ['title' => 'Customer Invoice'],
的用途吗?我在我的文件中设置了这样的脚本,但它没有在任何地方显示 客户服务。谢谢
【参考方案1】:
您可以使用属性文件名更改文件名:字符串,输出 PDF 文件名。
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
//Name for the file
'filename' => 'The_name_you_want',
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
'marginTop' => 5,
'marginLeft' => 5,
// your html content input
'content' => $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-1font-size:18px',
// set mPDF properties on the fly
'options' => ['title' => 'Customer Invoice'],
// call mPDF methods on the fly
'methods' => [
// 'SetHeader'=>['Krajee Report Header'],
// 'SetFooter'=>['PAGENO'],
]
]);
// return the pdf output as per the destination setting
return $pdf->render();
【讨论】:
以上是关于Yii2 mpdf更改下载的文件名的主要内容,如果未能解决你的问题,请参考以下文章
来自 HTML 中的新页面 kartik\mpdf (Yii2)
Yii2 - kartik-v/mpdf - 标题仅在第一页