FPDF error sending output to browser

不羁的心 提交于 2019-12-12 03:46:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!