我正在使用 mPDF 库从 HTML 页面生成 PDF 文件。它在 firefox 中运行良好,但在 chrome 浏览器中不显示 PDF 文件。
在 chrome 中生成 PDF 时出现以下错误。
以下是我使用 mPDF 生成 PDF 的代码
ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $yourFileName . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
$mpdf = new PDF( 'c','A4','','',15, 15,10,14,0,0);
$mpdf->useOnlyCoreFonts = false;
$mpdf->SetDisplayMode('real');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$stylesheet = file_get_contents(APPPATH . 'third_party/mpdf/style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output();
原文由 Ketav 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是人们在更旧版本的 Chrome 上遇到的问题。如果您仍然看到此问题,请执行以下操作
在 Google Chrome 中,您有 2 个选项来查看 PDF 文件。您可以使用 Chrome pdf 查看器(默认),也可以使用 Adobe Reader
您可以查看 chrome://plugins(在地址栏中输入)吗?并通过启用它切换到其他 PDF 查看器(Chrome/Adobe)!