2016-12-21 42 views
1

我使用FPDF,並試圖輸出這樣的代碼一testpage: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

我會真的很高興,如果有人可以幫助我。

+0

嘗試使用ob_clean()在開始和ob_end_flush和代碼 – rahulsm

+0

末幫我。現在它工作。謝謝! :) – luki512

+0

我已經給出了更詳細的解答答案塊 – rahulsm

回答

0

試試這個

<?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) 
?>