我尝试使用fpdf在php代码中生成pdf文件。但是当我在项目中运行此代码时,这是我得到的输出:FPDF错误:某些数据已经输出,无法发送PDF文件(输出从C:\ xampp \ htdocs \开始的header.php:92)。 header.php不是写入此脚本的文件。我尝试使用ob_clean();和ob_end_flush();.但它不起作用。
<?php
require("fpdf/fpdf.php");
$pdf = new FPDF();
global $DB;
$orderID=$_REQUEST['garID'];
$sql = "SELECT * FROM `" . $DB->pre . "garorder` WHERE garID= '" . $orderID . "'";
$d = $DB->dbRow($sql);
echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];
$pdf->AddPage();
$pdf->Rect(5, 5, 200, 287, 'D');
$pdf->Cell(10);
$pdf->SetFont("Arial","B","8");
$pdf->SetXY (10,30);
$pdf->MultiCell(50,5," ",1,1);
$pdf->Ln();
$pdf->SetFont('helvetica','B',10);
$pdf->Cell(190,7,'Order Details',1,2,'C');
$pdf->SetFont('helvetica','',10);
$y= $pdf->GetY();
$pdf->MultiCell(95,8, "Garment ID: "."\nParty Code: "."\nOrder Date: " , 'LRB',1 );
//$x= $pdf->GetX();
//$pdf->setXY($x+95,$y);
$pdf->Cell(90);
$pdf->SetFont('helvetica','',10);
$pdf->SetXY (105,62);
$pdf->MultiCell(95,12, "Name: "."\nDelivery Status: " , 'LRB',1 );
$pdf-> Ln();
$pdf->Cell(32,10,'Material Description',1,0,'L',0);
$period = 50;
for($x=36;$x <=$period; $x=$x+2){
$pdf->Cell(20,10,$x,1,0,'L',0);
}
$pdf->Output();
?>
答案 0 :(得分:0)
删除
echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];
这将解决它。
或分别在开头和结尾添加ob_start();
和ob_end_flush();
,如下所示:
<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush();
?>
以下是一些很好的例子FPDF error: Some data has already been output, can't send PDF