Reputation: 237
I'm using FPDF and trying to output a testpage with code like this:
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
I searched a lot on the internet, but they are always telling that I have to use a newer version or other things that didn't work on my project.
Here is the full error:
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
I would be really happy if someone could help me.
Upvotes: 2
Views: 8494
Reputation: 18557
Try this
<?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)
?>
Upvotes: 1