mpdf not working in Google Chrome but working fine in firefox

回眸只為那壹抹淺笑 提交于 2019-12-03 21:40:06

问题


Again am stuck into a situation while creating PDF document usong mPDF. I have done the following code which works fine in Firefox and Safari but not working in Google Chrome.

require_once 'mpdf60/mpdf.php';
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; 
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($test, 2);
$mpdf->Output();  

Can anyone please guide me on how to resolve this issue?


回答1:


According to your comment, try this before you send output:

ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $yourFileName . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');

require_once 'mpdf60/mpdf.php';
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; 
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($test, 2);
$mpdf->Output();  
ob_end_flush();



回答2:


I had the same problem, i just added the extension with filename inside output function

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

Now it is working in both firefox and chrome.

This is my code:-

$html = "<h1> Isac Yara </h1>"; $mpdf = new \Mpdf\Mpdf(); $mpdf->WriteHTML($html, 2); $mpdf->Output("myfile.pdf", 'D');



来源:https://stackoverflow.com/questions/28451161/mpdf-not-working-in-google-chrome-but-working-fine-in-firefox

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