我尝试使用FPDF生成pdf文件,但在执行时会出现此错误。
FPDF错误:某些数据已经输出,无法发送PDF文件 (输出从C:\ xampp \ htdocs \ nirman.siyaram.com \ header.php:250开始)
错误恰好位于header.php
开始的<?php
文件中。我尝试使用ob_start,ob_end_clean和类似的东西。但它没有用。
////////THE PDF FILE/////////
<?php
$pdf = new FPDF();
global $DB;
$view=$_REQUEST['vbeln'];
require("fpdf/fpdf.php");
$sql = "SELECT * FROM `" . $DB->pre . "party_outstanding_history` WHERE BELNR= '". $view ."'";
$rows = $DB->dbRow($sql);
$custCode= $rows['KUNNR'];
$docDate= $rows['AUGDT'];
$sql1 ="SELECT * FROM `" . $DB->pre . "party_master` WHERE KUNNR = '". $custCode."'";
$rows1 = $DB->dbRow($sql1);
$partyname = $rows1['NAME1'];
$pdf->AddPage();
$pdf->Rect(5, 5, 200, 287);
$pdf->SetFont('helvetica','B',12);
$pdf->Text(90,15,'JHAMPSTEAD DIVISION',1,2,'C');
$pdf->Text(70,20,'DEBIT/CREDIT NOTE',1,2,'C');
$pdf->SetFont('helvetica','',10);
$pdf->Text(10,35,'Doc No :',1,2,'C');
$pdf->Text(120,35,'Doc Date :',1,2,'C');
$pdf->Text(10,40,'Customer :',1,2,'C');
$pdf->Text(10,45,'Customer Name :',1,2,'C');
$pdf-> Ln();
$pdf->Text(10,60,'Agent :',1,2,'C');
$pdf->Text(10,65,'Reference :',1,2,'C');
$pdf->Text(10,70,'Text :',1,2,'C');
$pdf-> Ln();
$pdf->SetFont('Arial','B',9);
$pdf->SetXY(11,103);
$pdf->Cell(25,7,'BILL NO.',1,0,'L',0);
$pdf->Cell(22,7,'DATE',1,0,'L',0);
$pdf->Cell(22,7,'AMOUNT',1,0,'L',0);
$pdf->Cell(18,7,'LDAYS',1,0,'L',0);
$pdf->Cell(18,7,'EP1',1,0,'L',0);
$pdf->Cell(18,7,'EP2',1,0,'L',0);
$pdf->Cell(22,7,'INTDR1',1,0,'L',0);
$pdf->Cell(22,7,'INTAMT',1,0,'L',0);
$pdf->Cell(18,7,'NET',1,0,'L',0);
$pdf-> Ln();
$pdf-> Ln();
$pdf->SetX(11);
$pdf->Cell(47,7,'TOTAL',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Ln();
$pdf->SetX(156);
$pdf->Cell(22,7,'Net Amt.',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->SetFont("Arial","B","8");
$pdf->SetXY (5,271);
$pdf->Output();
?>
////////// END //////////
/////////的header.php //////
<body>
<div style=" background-color: black; " id="mySidenav" class="sidenav">
<li><a href="javascript:void(0)" onclick="w3_close()" style="color:white;" class="closebtn">Close ×</a></li>
<ul class="panel panel1 panel-default" style="margin-left:-32px;">
<?php /////LINE 250/////
echo getMenu("MAIN");
?>
</ul>
</div>
<nav class="navbar navbar-inverse" data-spy="affix">
<div class="navbar-header">
<a class="center" onclick="w3_open()" id="" style="font-size:20px;cursor:pointer"><span style="color:white;" class="glyphicon glyphicon-align-justify"></span></a>
<a class="navbar-brand pull-right" href="<?php echo SITEURL;?>/" title="logo"><img style="width:120px;height:30px;" src="<?php echo SITEURL; ?>/images/siyaram-logo.jpg"/></a>
</div>
<?php if(isset($_COOKIE['PARTYCODE'])) { ?>
<div style="" class="topnav pull-right" id="myTopnav">
<a href="#" style="color:white;"><label style="margin:0px;">Welcome, <?php echo $_COOKIE['PARTYNAME'];?></label></a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunctionNew()">☰</a>
<a href="<?php echo SITEURL."/mainform1/x-mainform1/"?>"><label style="color:white;">Profile</label><span class=""></span></a>
<a href="#"><label style="color:white;">FY : <?php if(date("m") > 3 ){echo date("Y")."-".(date("Y")+1); }else{ echo (date("Y")-1)."-".date("Y");}?></label></a>
<a href="<?php echo SITEURL."/cart/cart-detail/"?>"><span class="glyphicon glyphicon-shopping-cart" style="color:white;"></span><label style="color:white;">Cart</label></a>
<a href="<?php echo SITEURL;?>/?xAction=xLogout" title="logout"><span class="glyphicon glyphicon-off" style="color:white;"></span><label style="color:white;"> Logout</label></a>
</div>
<?php } ?>
</nav>
</body>
///////END///////
///////////// FPDF.PHP ////////////
function Output($dest='', $name='', $isUTF8=false)
{
// Output PDF to some destination
$this->Close();
if(strlen($name)==1 && strlen($dest)!=1)
{
// Fix parameter order
$tmp = $dest;
$dest = $name;
$name = $tmp;
}
if($dest=='')
$dest = 'I';
if($name=='')
$name = 'doc.pdf';
switch(strtoupper($dest))
{ //////LINE 996////////
case 'I':
// Send to standard output
$this->_checkoutput();
if(PHP_SAPI!='cli')
{
// We send to a browser
header('Content-Type: application/pdf');
header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
}
echo $this->buffer;
break;
case 'D':
// Download file
$this->_checkoutput();
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo $this->buffer;
break;
case 'F':
// Save to local file
if(!file_put_contents($name,$this->buffer))
$this->Error('Unable to create output file: '.$name);
break;
case 'S':
// Return as a string
return $this->buffer;
default:
$this->Error('Incorrect output destination: '.$dest);
}
return '';
}