Auto download mpdf generated pdf document

Mansoor Jafar picture Mansoor Jafar · Aug 27, 2012 · Viewed 51.2k times · Source

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 .

Answer

Mihai Iorga picture Mihai Iorga · Aug 27, 2012

Add 'D' parameter for download

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