【问题标题】:Fatal error using FPDF:Some data has already been output, can't send PDF file?使用 FPDF 时出现致命错误:一些数据已经输出,无法发送 PDF 文件?
【发布时间】:2010-08-20 10:52:51
【问题描述】:

当我尝试创建 PDF 文件时出现以下错误?
我不知道为什么,我不知道如何解决它? 错误如下所示
`

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\phpexample\createpdf.php:1) in C:\xampp\htdocs\phpexample\fpdf16\fpdf.php on line 1017`<br/>
`FPDF error: Some data has already been output, can't send PDF file`<br/>

我的编码是这样的

 <?php
 include_once('fpdf16/fpdf.php');$pdf=new FPDF();

$pdf->AddPage();
$reportdate = date('d-m-Y H:i:s');
$filename = $reportdate.'_report.pdf';
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
$pdf->SetLineWidth(.3);
$pdf->SetFont('Arial', 'B', 6);
// Header
$header=array('Member Card No','Full Name','Description', 'Start Date', 'Expiry Date', 'ramount', 'Address1', 'Address2');
$w = array(25, 35, 35, 15, 18, 15, 30, 30);
for($i=0;$i<count($header); $i++)
        $pdf->Cell($w[$i],7, $header[$i], 1, 0, 'L', true);

$pdf->Ln();

// Reset colour set for data 
$pdf->SetFillColor(224,235,255);
$pdf->SetTextColor(0);
$pdf->SetFont('courier','',7);
$fill=false;
$resultcount=8;
for($i=0;$i<$resultcount;$i++)
{
        $height =6;
        $pdf->Cell($w[0], '$height', 'CardNoishai', '1', '0', 'L', $fill);
        $pdf->Cell($w[1], '$height', 'Vinoth', '1', '0', 'L', $fill);
        $pdf->Cell($w[2], '$height', 'Sample PDF', '1', '0', 'L', $fill);
        $pdf->Cell($w[3], '$height', date('m-d-y'), '1', '0', 'L', $fill);
        $pdf->Cell($w[4], '$height', date('m-d-y'), '1', '0', 'L', $fill);
        $pdf->Cell($w[5], '$height', 'test', '1', '0', 'L', $fill);
        $pdf->Cell($w[5], '$height', 'test', '1', '0', 'L', $fill);
        $pdf->Cell($w[5], '$height', 'Add2', '1', '0', 'L', $fill);
        $pdf->Ln();
        $fill = !$fill;

}       
$pdf->Cell(array_sum($w),0,'','T');
$pdf->Output($filename, 'I');
?>

【问题讨论】:

  • 也许你必须从 utf-8 改为 ansi

标签: php


【解决方案1】:

去掉开始php标签前的空格。

【讨论】:

    【解决方案2】:

    &lt;?php 之前有一个空格。删除它,因为它会导致它在 PHP 代码运行之前被输出。

    【讨论】:

    • @Davide Gualano,@Artefacto 如何将图像添加到此 PDF 以及如何为不同的行设置不同的字体。例如,在第一行中,我想让它加粗,在第二行中我想要用粗体使其斜体。有可能吗?
    • @vino,如果你想问一个新问题,请开始一个新的问题线程。
    • @Mike Sherov 不需要开始新的线程我得到了答案。它可以在 FPDF 教程中找到。谢谢大家
    最近更新 更多