[RESOLVED] fpdf php5 problem

liunx

Guest
Hello,

I have been using the same FPDF script with php4 for ages without a problem. I upgraded my server to php5 and hit one problem that I can't resolve.

The script basically generates a cover page for a quote, then the individual items for the quote. I loop through a series of rows all with the same height (in this loop). They correspond to about 3 rows of data per A4 page. The cover page and the first A4 page prints fine, but after the pagebreak the fourth row appears at the bottom of the next page, then after that it becomes unpredictable to the extent that it can print multiple empty pages, or throw individual cells down the pages (a mess). I also use the CheckPageBreak from the mc_table class which is included before the code shown. I have lifted the function CheckPageBreak out of the mc_table class for reference. I have also used this with the tcpdf version and get the same results. Completely baffled.

This is the relevant bit of code, I would appreciate any help. I have two sites that really need to be sorted!

//the function CheckPageBreak from the mc_table class included earlier

function CheckPageBreak($h)
{
//If the height h would cause an overflow, add a new page immediately
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}

//this is the relevant part of my script not including the cover page

//Disable automatic page break
$pdf->SetAutoPageBreak(false);

//Add first page
$pdf->AddPage();

//set initial y axis position per page
$y_axis_initial = 20;

$y_axis = $y_axis_initial;

$pdf->SetX(135);
$pdf->SetFont('Arial','B',10);
$pdf->SetFillColor(255,255,255);
$pdf->Cell(60,6,"Quotation Number: " . $quotation,0,0,'R',1);
$pdf->Ln();
$pdf->Image('../images/Main_Image.jpg',13,5,70,17);
$pdf->Ln(20);
$pdf->SetFont('Arial','B',10);
$pdf->SetY($y_axis);
$pdf->SetX(15);
$pdf->Cell(61,6,'IMAGE','B',0,'L',1);
$pdf->Cell(60,6,'DESCRIPTION','B',0,'L',1);
$pdf->Cell(15,6,'QUAN','B',0,'R',1);
$pdf->Cell(20,6,'UNIT','B',0,'R',1);
$pdf->Cell(25,6,'TOTAL','B',0,'R',1);

//Select the Products you want to show in your PDF file
$query = "SELECT * FROM db.table WHERE QuoteIndex LIKE $quotation ORDER BY finalID";
$result = mysql_query($query) or die("Couldn't execute query");

//Set Row Height
$image_row_height = 62;
$space_between_rows= 10;

while($row = mysql_fetch_array($result))
{
// format data into text
$PresID = $row['PresID'];
$ProdQuan= $row['ProdQuan'];
$ProdFinish = $row['ProdFinish'];
$ProdPrice = $row['ProdPrice'];
$linevalue = $ProdQuan*$ProdPrice;
$linevalue = number_format($linevalue, 2);
$linevalue = $CurrSymb . $linevalue;
$ProdPrice = number_format($ProdPrice, 2);
$ProdPrice = $CurrSymb . $ProdPrice;
$description = $row['datadesc'];
$dim = $row['ProdDim'];
$image = $row['imageindex'];
$model = $row['ProdModel'];
$Dimchange = str_replace("<br />","\n",$dim);
$desctxt = $description . "\n\nW x D x H (Seat Height) c.m.:\n" . $Dimchange . "\n\n" . $ProdFinish;

//This is the bit with the problem... I think. Works perfectly for the first 3 rows, then page break and chaos.

if(!empty($image)){
//check for pagebreak
if ($pdf->CheckPageBreak($image_row_height) == 1){
$y_axis = $y_axis_initial;
}
$pdf->SetFont('Arial','',10);
$pdf->SetY(($y_axis)+7);
$pdf->SetX(15);
$pdf->MultiCell(60,5,strtoupper($model),0,'L');
$pdf->SetX(15);
$pdf->Image('http://www.mysite.co.uk'.$image,$pdf->GetX(),($pdf->GetY()),60,60,'JPG');
$pdf->SetY(($y_axis+7));
$pdf->SetX(76);
$pdf->MultiCell(60,5,$description,1,'J');
$pdf->SetX(76);
$pdf->ln(2);
$pdf->SetX(76);
$pdf->Cell(60,5,"Centimetres W x D x H (Seat):",0,0,'L',1);
$pdf->ln();
$pdf->SetX(76);
$pdf->MultiCell(60,5,$Dimchange,1,'J');
$pdf->SetX(76);
$pdf->ln(2);
$pdf->SetX(76);
$pdf->Cell(60,5,"Further Details:",0,0,'L',1);
$pdf->ln();
$pdf->SetX(76);
$pdf->MultiCell(60,5,$ProdFinish,0,'J');
$pdf->SetY(($y_axis+7));
$pdf->SetX(135);
$pdf->Cell(15,5,$ProdQuan,0,0,'R',1);
$pdf->Cell(20,5,$ProdPrice,0,0,'R',1);
$pdf->Cell(25,5,$linevalue,0,0,'R',1);
//Go to next row
$y_axis = $y_axis + $image_row_height + $space_between_rows;
$pdf->SetY($y_axis);
}
else {not relevant to thread}I have sorted this. The function CheckPageBreak was not returning anything to the if statement. So I explicitly changed it to do so. And is now working. What I dont understand is why this only occurred after an upgrade to php5 when by rights it should have broken in php4 as well. :bemused:
 
Back
Top