PHP FPDF无法在Chrome中加载PDF文档

kri*_*a89 5 php pdf google-chrome fpdf

我正在尝试使用fpdf库和php生成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();
?>
Run Code Online (Sandbox Code Playgroud)

web*_*sky 1

我知道这个老问题,但评论中有人要求答案。不要设置标题。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');
?>
Run Code Online (Sandbox Code Playgroud)

我还推荐http://www.fpdf.org/