【问题标题】:PHP FPDF Failed to load PDF document in ChromePHP FPDF 无法在 Chrome 中加载 PDF 文档
【发布时间】:2016-10-14 00:34:05
【问题描述】:

我正在尝试使用带有 php 的 fpdf 库生成一个 pdf 文档,但我在 chrome 中收到错误 Failed to load PDF document。我能够在 Firefox 中正确查看文档。下面是我试图生成pdf的代码。有人可以帮忙吗?提前致谢。

<?php
 ini_set('display_startup_errors', 1);
 ini_set('display_errors', 1);
 error_reporting(-1);
 ob_start();
 $pdf = new FPDF();
 $pdf->AddPage();
 $pdf->SetFont('Arial', 'B', 16);
 $pdf->Cell(40, 10, 'Hello World!');
 header('Content-type: application/pdf');
 header('Content-Transfer-Encoding: binary');
 header("Content-Disposition: inline; filename='example2.pdf'");
 $pdf->Output('example2.pdf', 'I');
 ob_end_flush();
?>

【问题讨论】:

  • 在我的 chrome 中它工作正常。希望你不要忘记include('fpdf/fpdf.php');
  • 是的,我已经包含了fpdf.php,事实上我可以在 Firefox 中查看该文件。
  • 那么解决了吗?如果是,请发布答案。
  • @krishna89:你解决了这个问题吗?
  • 在这里尝试解决方案stackoverflow.com/questions/45101160/…

标签: php google-chrome pdf fpdf


【解决方案1】:

我知道这个老问题,但在 cmets 中有寻求答案的请求。 不要设置标题。 FPDF 生成它们。

<?php
   require('fpdf.php');

   $pdf = new FPDF();
   $pdf->AddPage();
   $pdf->SetFont('Arial','B',16);
   $pdf->Cell(40,10,'Hello World!');
   $pdf->Output('example2.pdf', 'I');
?>

我也推荐enter link description here

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2022-07-11
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    相关资源
    最近更新 更多