mpdf无法在Google Chrome浏览器中运行,但在Firefox中可以正常运行

问题描述 投票:3回答:2

再次在使用mPDF创建PDF文档时陷入困境。我已完成以下代码,该代码在Firefox和Safari中可以正常运行,但在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();  

任何人都可以指导我如何解决此问题?

php mpdf
2个回答
5
投票

根据您的评论,请在发送输出之前尝试以下操作:

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();

0
投票

我有同样的问题,我只是在输出函数中添加了带有文件名的扩展名

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

现在它可以在Firefox和chrome中使用。

这是我的代码:-

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

© www.soinside.com 2019 - 2024. All rights reserved.