Reputation: 31
Here is my code:
<?php
define('FPDF_FONTPATH','../../fpdf/font/');
require('../../fpdf/fpdf.php');
$pdf = new FPDF('L','mm','A4');
$pdf->Open();
$pdf->AddPage();
function codes($total,$mark){
$perc = $mark/$total*100;
if($perc >= 94){echo "A1";}
if($perc >= 84 && $perc<= 93){echo "A2";}
if($perc >= 72 && $perc<= 83){echo "B1";}
if($perc >= 60 && $perc<= 71){echo "B2";}
if($perc >= 49 && $perc<= 59){echo "C1";}
if($perc >= 40 && $perc<= 48){echo "C2";}
if($perc >=0 && $perc<= 40){echo "D";}
}
$pdf->SetFont('Arial','',10);
$pdf->Ln();
$pdf->Cell(30,8,'English',1,0,'L',0,'');
$pdf->Cell(15,8,codes(25,$fa1enga),1,0,'C',0,'');
$pdf->output();
But when I run this PHP code it prints:
B2FPDF error: Some data has already been output, can't send PDF file
Please help me to show the text "B2" or whatever in fpdf cell.
Upvotes: 1
Views: 1117
Reputation: 1998
Your codes
function will output the result of its calculation to the client instead of returning it. For FPDF to work properly, there must not be any output at all except that from FPDF itself.
Replace all occurrences of echo
in your codes
function with return
.
Upvotes: 2