I am using MPdf of version 8.0 and PHP version 7.1.
This is my code.
function generatePDF($order){
$html = getHTML($order);
try {
$mpdf = new MpdfMpdf(['margin_left' => 20,
'margin_right' => 15,
'margin_top' => 48,
'margin_bottom' => 25,
'margin_header' => 10,
'margin_footer' => 10]);
$mpdf->SetProtection(array('print'));
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('ABCD.pdf','I');
}catch (MpdfMpdfException $e) { // Note: safer fully qualified exception name used for catch
// Process the exception, log, print etc.
$error = $e->getMessage();
echo $e->getMessage();
}
This code is working perfectly for desktop. If I use my laptop or any desktop, it generate PDF very well. But, When I am checking it on mobile device, it do not downloading any PDF. It is also not throwing any exceptions or errors.
I have debugged each code line, every line is executed very well as expected just not generating PDF.
2
Answers
Instead of
I
parameter in$mpdf->Output('ABCD.pdf','I');
, you can useF
parameter. See the link here for more information.F
parameter create the file in the server in specific directory without any problem that usually cause when usingI
orD
parameter:$mpdf->Output('/DIRABCD.pdf','F');
After that you can force the browser (mobile or PC) to download the file using
readfile()
orfread()
functions in PHP.The code would be like this:
Try to get you buffer clean before writing the HTML to pdf. Here is your updated code.