mpdf不适用于谷歌Chrome,但在firefox中运行良好


mpdf not working in Google Chrome but working fine in firefox

在使用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();  

有人能指导我如何解决这个问题吗?

根据您的评论,在发送输出之前尝试一下:

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

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

$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');