如何修复PDF“无法加载PDF文档”。在Chrome中使用MPDF
我正在尝试从我的网站查看下载的PDF文件,但是它显示此未能在所有浏览器中加载PDF文档。
。有人对这个问题有任何想法吗?
<?php
}
$body = ob_get_clean();
$body = iconv('UTF-8', 'UTF-8//IGNORE', $body);
$body = iconv('UTF-8', 'UTF-8//TRANSLIT', $body);
include("mpdf/mpdf.php");
$mpdf=new \mPDF('+aCJK','A4','','' , 35, 0, 0, 0, 0, 0);
$mpdf->SetAutoFont();
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$stylesheet = file_get_contents('pdf.css'); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->WriteHTML($body);
$mpdf->Output($_POST["id"]."_".$_POST["year"].'.pdf','D');
}
}
?>
I'm trying to view my downloaded PDF file from my website, but it shows this Failed to load PDF document.
in all browser. Does anyone have any idea on this issue ?
<?php
}
$body = ob_get_clean();
$body = iconv('UTF-8', 'UTF-8//IGNORE', $body);
$body = iconv('UTF-8', 'UTF-8//TRANSLIT', $body);
include("mpdf/mpdf.php");
$mpdf=new \mPDF('+aCJK','A4','','' , 35, 0, 0, 0, 0, 0);
$mpdf->SetAutoFont();
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$stylesheet = file_get_contents('pdf.css'); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->WriteHTML($body);
$mpdf->Output($_POST["id"]."_".$_POST["year"].'.pdf','D');
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我恰好有这个问题。在寻求解决方案时,我在浏览器检查员中观察到我正在获得404响应标头,即使它在Firefox中渲染PDF也很好。显然,Firefox只是不在乎这一点,无论如何都会捕获/呈现数据。但是,Chrome是固定的。
因此,我强迫这个问题:
这为我解决了问题。
I had exactly this issue. In seeking the solution, I observed in the browser inspector that I was getting a 404 response header, even though it was rendering the PDF in Firefox just fine. Apparently, Firefox just didn't care about that, and catches/renders the data anyway. Chrome, however, was being intransigent.
So I forced the issue:
This solved the problem for me.