[英]“Network failure” to download PDF generated with with PHP FPDF/FPDF2File class in Google Chrome
我在PHP / FPDF / FPDF2File中生成了报告,这些报告通常显示在浏览器窗口中。
注意:
尝试保存已在 Google Chrome 上打开并显示的 PDF 时,出现以下错误:
失败 - 网络错误
因此,您不能保存PDF,除非您去打印和打印PDF,或者打印PDF PDF,这没有多大意义。
有人能告诉如何解决这个错误吗?
非常感谢!
您是否设置了 Cache-Control 标头的 no-store 属性?
我不知道为什么,但对我来说它在改变后有效
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
到
header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");
@Amryn 的回答实际上对我有用。 这是我的完整标题设置:
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="relatorio-clientes.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen(ltrim($content)));
header('Accept-Ranges: ' . strlen(ltrim($content)));
echo $content;
如果您使用打印选项并另存为 PDF,则不会发生网络错误(解决方法)。
这对我有用:
删除php关闭标签后的所有字符,如空格?>
在这里找到: https : //stackoverflow.com/a/13463631/2267379
简单的解决方案:不要做
return $pdf->Output('medienpass.pdf', 'D');
在您的 getPdf() 函数中,因为输出将包含在大量 html 代码中。
而是仅将您的 pdf 返回给客户:
die($pdf->Output('medienpass.pdf', 'D'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.