我正在尝试使用带有 php 的 fpdf 库生成一个 pdf 文档,但我在 chrome 中收到一个错误,因为 无法加载 PDF 文档
。我能够在 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();
?>
最佳答案
我知道这个老问题,但是评论里有求解答的。 不要设置标题。 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');
?>
关于PHP FPDF 无法在 Chrome 中加载 PDF 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37792321/