FPDF 错误 "Some data has already been output"

FPDF Error "Some data has already been output"

我正在使用 FPDF 并尝试使用如下代码输出测试页:

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

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

我在互联网上搜索了很多,但他们总是告诉我必须使用更新的版本或其他不适用于我的项目的东西。

这是完整的错误:

Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file in /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/fpdf/fpdf.php:271 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/fpdf/fpdf.php(1051): FPDF->Error('Some data has a...') #1 /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/fpdf/fpdf.php(987): FPDF->_checkoutput() #2 /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/sites/bestellung_abschluss.php(8): FPDF->Output() #3 /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/sites/main.php(86): include('/Applications/X...') #4 /Applications/XAMPP/xamppfiles/htdocs/businessanwendungen/index.php(18): include('/Applications/X...') #5 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/BusinessAnwendungen/fpdf/fpdf.php on line 271

如果有人能帮助我,我会很高兴。

试试这个

  <?php
require('fpdf/fpdf.php');
ob_end_clean(); //    the buffer and never prints or returns anything.
ob_start(); // it starts buffering
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush(); // It's printed here, because ob_end_flush "prints" what's in
              // the buffer, rather than returning it
              //     (unlike the ob_get_* functions)
?>