在pdf输出期间,codeigniter和fpdf代码块


codeigniter and fpdf code blockin during pdf output

我对fpdf 有一个大问题

在我的页面中,我有很多代码,最后我用这个示例创建了一个pdf文件:

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
ob_end_clean();
$pdf->Output();

结果是,只有pdf的创意被制作出来,其他代码都没有!

首先,样本的代码是:

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
//ob_end_clean();
$pdf->Output();

像这样,之前的代码执行起来没有问题,但不是pdf,我在浏览器上收到了这个:

FPDF error: Some data has already been output, can't send PDF file

你能帮我吗?我是fpdf库的新手

这是因为php代码已经向浏览器输出了一些数据。在调用$pdf->Output()之前,请检查您的php是否尚未向浏览器写入任何数据(标头除外),从而避免发送末尾附加了pdf二进制数据的未知数据。

ob_end_clean()函数调用确保您的脚本清除php脚本以前可能产生的任何输出。