gpt4 book ai didi

php - chrome 浏览器加载 PDF 文档失败

转载 作者:可可西里 更新时间:2023-10-31 23:11:35 33 4
gpt4 key购买 nike

我正在使用 mPDF 库从 HTML 页面生成 PDF 文件。它在 firefox 中运行良好,但在 chrome 浏览器中不显示 PDF 文件。

我在 chrome 中生成 PDF 时遇到以下错误。

Getting error in chrome browser while generating 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();

最佳答案

当您使用 html 到 PDF 的库(例如 mPDF)时也会发生这种情况,并且您在发送文件之前以某种方式将 HTML 发送到浏览器。许多读者在阅读 PDF 标记之前会忽略 HTML - Chrome 不会。

例如,在 PHP 中,在将数据发送到 mPDF 之前清除输出缓冲区:ob_clean()

关于php - chrome 浏览器加载 PDF 文档失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34737498/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com