Auto download mpdf generated pdf document

2019-02-07 20:43发布

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 .

标签: php html mpdf
2条回答
Root(大扎)
2楼-- · 2019-02-07 20:49

Add 'D' parameter for download

$mpdf->Output('MyPDF.pdf', 'D');
查看更多
乱世女痞
3楼-- · 2019-02-07 20:57

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);
}
查看更多
登录 后发表回答