Auto download mpdf generated pdf document

隐身守侯 提交于 2019-11-30 14:31:01

问题


I am newbie for mpdf so don't mind if you feel this question is stupid one:),

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..

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->download instead $mpdf->Output('mpdf.pdf').I searched alot for this type solution but in vain i could't find any .


回答1:


Add 'D' parameter for download

$mpdf->Output('MyPDF.pdf', 'D');



回答2:


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);
}


来源:https://stackoverflow.com/questions/12139204/auto-download-mpdf-generated-pdf-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!