问题描述
我收到此错误消息:
fpdf错误:某些数据已经输出,无法发送PDF文件
当我启动以下代码时;你知道为什么吗?你能帮我吗?
$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++; }
推荐答案
对于FPDF工作,不能有任何其他输出. PHP文件中其他位置,echo语句之类的内容,<?php ?>标签之前或之后的任何内容(包括空格)等都会导致该错误消息.
我怀疑您的PHP文件中的其他地方,可能有一些非FPDF输出导致您看到该错误.
其他推荐答案
它是代码中某个地方的beacuse,然后在输出您已经完成了一些echo或var_dump或任何其他输出Metod之前. 使用header输出数据时,您无法在header语句向标准输出
上发送其他任何内容其他推荐答案
在这里使用输出缓冲: -
发送之前,使用ob_clean();发送输出清洁输出缓冲区.
ob_clean();//add this line $pdf->Output($namefilepdf,'D');
请参阅此 link p>
问题描述
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++; }
推荐答案
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.
其他推荐答案
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
其他推荐答案
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();