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 .

有帮助吗?

解决方案

Add 'D' parameter for download

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

其他提示

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top