问题
I am getting this error message:
FPDF error: Some data has already been output, can't send PDF file
when I launch the following code; do you know why? can you help me?
$i = 0;
while ($i <= $y)
{
$namefilepdf=$x_labelname.$i.'.pdf';
$pdf=new FPDF();
$pdf->AddPage($x_lay,$x_dimpag);
$pdf->SetFont('Arial');
if (isset($x_toprint1))
if ($x_toprint1=='on')
if (isset($x_progressive1))
{
if ($x_progressive1=='on')
{
$pdf->SetFontSize($x_font1);
$pdf->Text($x_coordx1,$x_coordy1,$x_val1+$i);
}
}
else
{
$pdf->SetFontSize($x_font1);
$pdf->Text($x_coordx1,$x_coordy1,$x_valore1);
}
$pdf->Output($namefilepdf,'D');
$i++;
}
回答1:
For FPDF to work, there can't be any other output. Things like echo
statements elsewhere in your PHP file, anything (including spaces) before or after your <?php ?>
tags, etc. will cause that error message.
I suspect that somewhere else in your PHP file, there's probably some non-FPDF output that's causing you to see that error.
回答2:
it's beacuse somewhere in your code before outputing you pdf object you have already done some echo
or var_dump
or any other output metod.
when outputing data using header
you can not send anything else before the header
statement to the standard output
回答3:
Use output buffering here :-
Before send to output clean the output buffer using ob_clean();
.
ob_clean();//add this line
$pdf->Output($namefilepdf,'D');
Please refer this link to know about ob_clean();
来源:https://stackoverflow.com/questions/15137072/fpdf-error-sending-output-to-browser