Hi all,

I am trying to write a script that produces a PDF using FPDF. So far so good but what I would like to do is display a set number of rows produced by a query and when the row limit is met create another page.

At the moment all the data is idsplayed until the end of the page and then overflows in to nowhere.

My current code is:


//Instanciation of inherited class
$pdf=new PDF();
$pdf->SetAutoPageBreak(false);
$pdf->AliasNbPages();
$pdf->AddPage();



//Initialize the 3 columns and the total
$column_room = "";
$column_auditdate = "";
$column_auditby = "";
$column_hot = "";
$column_cold = "";
$column_comment = "";

//For each row, add the field to the corresponding column
while($row_Water = mysql_fetch_array($Water)){
    $room = $row_Water["Room"];
    $auditdate = date("d-m-Y", strtotime($row_Water["InspectDate"]));
    $auditby = $row_Water["AuditBy"];
	$hot = $row_Water["SeqID1306"];
	$cold= $row_Water["SeqID1307"];
    $comment = $row_Water["Comments"];
	$comment = (strlen($comment) > 50) ? substr($comment,0,50).'...' : $comment;
    $column_room = $column_room.$room."\n";
    $column_auditdate = $column_auditdate.$auditdate."\n";
    $column_auditby = $column_auditby.$auditby."\n";
	$column_hot = $column_hot.$hot."\n";
	$column_cold= $column_cold.$cold."\n";
	$column_comment = $column_comment.$comment."\n";

} 



$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    //Fields Name position
$Y_Fields_Name_position = 50;
//Table position, under Fields Name
$Y_Table_Position = 54;

//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',10);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(10);
$pdf->Cell(12,4,'Room',1,0,'L',1);
$pdf->SetX(22);
$pdf->Cell(20,4,'Audit date',1,0,'L',1);
$pdf->SetX(42);
$pdf->Cell(30,4,'Audit By',1,0,'L',1);
$pdf->SetX(72);
$pdf->Cell(15,4,'Hot',1,0,'L',1);
$pdf->SetX(87);
$pdf->Cell(15,4,'Cold',1,0,'L',1);
$pdf->SetX(102);
$pdf->Cell(100,4,'Comments',1,0,'L',1);
$pdf->Ln();

//Now show the 3 columns
$pdf->SetFont('Arial','',8);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(10);
$pdf->MultiCell(12,4,$column_room,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(22);
$pdf->MultiCell(20,4,$column_auditdate,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(42);
$pdf->MultiCell(30,4,$column_auditby,1,'L');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(72);
$pdf->SetTextColor(255, 0, 0); 
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(15,4,$column_hot,1,'L');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(87);
$pdf->MultiCell(15,4,$column_cold,1,'L');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(102);
$pdf->MultiCell(100,4,$column_comment,1,'L');


$pdf->Output();

What do I need to do to make it create a new page after say 40 rows have been displays.

Many thanks in advance, any help would be great.

Regards

Blackbox

    FPDF has its own forum - but why do you have this : $pdf->SetAutoPageBreak(false);
    anyway you have marked it resolved..

      Write a Reply...