php 自动下载mpdf生成的pdf文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12139204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto download mpdf generated pdf document
提问by Mansoor Jafar
I am newbie for mpdf so don't mind if you feel this question is stupid one:),
我是 mpdf 的新手,所以如果您觉得这个问题很愚蠢,请不要介意:),
I generated the pdf document usinf mPDF class , the issue is that after pdf generated the browser opens it in tab . But i want it not to open but auto download , My code is like follwing..
我用usinf mPDF 类生成了pdf 文档,问题是pdf 生成后浏览器在选项卡中打开它。但我希望它不是打开而是自动下载,我的代码就像下面一样..
include("../mpdf.php");
$html="my HTML code here !";
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output('mpdf.pdf');
I am expecting that there will be a function to download in the mpdf class like $mpdf->downloadinstead $mpdf->Output('mpdf.pdf').I searched alot for this type solution but in vain i could't find any .
我期待在 mpdf 类中有一个函数可以下载,$mpdf->download而不是$mpdf->Output('mpdf.pdf')。我搜索了很多这种类型的解决方案,但徒劳地我找不到任何 .
回答by Mihai Iorga
Add 'D' parameter for download
添加“D”参数以供下载
$mpdf->Output('MyPDF.pdf', 'D');
回答by Uttara
for downloading use this
下载使用这个
$filename = "mpdf.pdf";
if (file_exists($filename)) {
header('Content-type: application/force-download');
header('Content-Disposition: attachment; filename='.$filename);
readfile($filename);
}

