Reputation: 125
This is the code im using to make a list from data i get out a database. Im using a for each loop to put all data on screen since its a variable amout of data that comes out of the database.
Now im facing the problem that it stops when there are 38 lines of data... I have put SetAutoPageBreak(true, 10); but it does not seem to work.
I kindly aks if someone has a possible solution.
Thanks in forehand :)
$pdf = new FPDF('P','mm','A4');
$pdf->addPage(); $pdf->SetFont('Arial','B',16);
$pdf->SetMargins(10, 10);
$pdf->SetAutoPageBreak(true, 10);
// De kop
$pdf->SetTextColor(0,0, 0);
$pdf->Text(10, 15, "Balansformulier", TRUE);
$pdf->Text(10, 25, "#", TRUE);
$pdf->Text(30, 25, "Naam", TRUE);
$pdf->Text(100, 25, "Waar", TRUE);
$pdf->Text(154, 25, "Aanwezig?", TRUE);
$pdf->SetFont('Arial','i',11);
// horizontale waardes voor de variabelen
$x1=30;
$x2=100;
$x3=160;
// veritcale waardes voor de variabelen
$y=30;
$y2=27;
// waardes voor de nummers
$xnummer=10;
$ynummer=30;
$nummer=0;
//Waardes voor de lijnen
$xlijn=10;
$ylijn=31;
for($i=0; $i<5; $i++){
foreach($balans_lijst as $balans){
$nummer++;
$naam = $html_entities->html_ent($balans['naam']);
$waar = $html_entities->html_ent($balans['waar']);
$y = $y+7;
$y2 = $y2+7;
$ynummer = $ynummer+7;
$ylijn = $ylijn+7;
$pdf->SetXY($x1, $y);
//Stukken erop zetten
$pdf->Text($xnummer,$ynummer,"{$nummer}.",1,'L', TRUE);
$pdf->Text($x1,$y,"{$naam}",1,'L', TRUE);
$pdf->Text($x2,$y,"{$waar}",1,'L', TRUE);
$pdf->Line($xlijn, $ylijn, 190, $ylijn);
$pdf->Rect($x3, $y2, 3, 3);
}
}
Upvotes: 2
Views: 16876
Reputation: 257
It made a difference for me when I added it directly after creating the new object,
$pdf = new PDF();
$pdf->SetAutoPageBreak(true,10);
Upvotes: 1
Reputation: 3172
Reset x y and $pdf->AddPage();
(...)
//Stukken erop zetten
if($nummer % 38 === 0){
// horizontale waardes voor de variabelen
$x1=30;
$x2=100;
$x3=160;
// veritcale waardes voor de variabelen
$y=30;
$y2=27;
// waardes voor de nummers
$xnummer=10;
$ynummer=30;
//Waardes voor de lijnen
$xlijn=10;
$ylijn=31;
$pdf->AddPage();
}
$pdf->Text($xnummer,$ynummer,"{$nummer}.",1,'L', TRUE);
$pdf->Text($x1,$y,"{$naam}",1,'L', TRUE);
$pdf->Text($x2,$y,"{$waar}",1,'L', TRUE);
$pdf->Line($xlijn, $ylijn, 190, $ylijn);
(...)
Full example
$pdf = new \FPDF('P','mm','A4');
$pdf->addPage(); $pdf->SetFont('Arial','B',16);
$pdf->SetMargins(10, 10);
$pdf->SetAutoPageBreak(true, 10);
// De kop
$pdf->SetTextColor(0,0, 0);
$pdf->Text(10, 15, "Balansformulier", TRUE);
$pdf->Text(10, 25, "#", TRUE);
$pdf->Text(30, 25, "Naam", TRUE);
$pdf->Text(100, 25, "Waar", TRUE);
$pdf->Text(154, 25, "Aanwezig?", TRUE);
$pdf->SetFont('Arial','i',11);
// horizontale waardes voor de variabelen
$x1=30;
$x2=100;
$x3=160;
// veritcale waardes voor de variabelen
$y=30;
$y2=27;
// waardes voor de nummers
$xnummer=10;
$ynummer=30;
$nummer=0;
//Waardes voor de lijnen
$xlijn=10;
$ylijn=31;
for($i=0; $i<5; $i++){
for($i=0; $i<500; $i++){
$nummer++;
$naam = 'XXXXXX';
$waar = 'XXXXXXXXXX';
$y = $y+7;
$y2 = $y2+7;
$ynummer = $ynummer+7;
$ylijn = $ylijn+7;
$pdf->SetXY($x1, $y);
//Stukken erop zetten
if($nummer % 38 === 0){
// horizontale waardes voor de variabelen
$x1=30;
$x2=100;
$x3=160;
// veritcale waardes voor de variabelen
$y=30;
$y2=27;
// waardes voor de nummers
$xnummer=10;
$ynummer=30;
//Waardes voor de lijnen
$xlijn=10;
$ylijn=31;
$pdf->AddPage();
}
$pdf->Text($xnummer,$ynummer,"{$nummer}.",1,'L', TRUE);
$pdf->Text($x1,$y,"{$naam}",1,'L', TRUE);
$pdf->Text($x2,$y,"{$waar}",1,'L', TRUE);
$pdf->Line($xlijn, $ylijn, 190, $ylijn);
$pdf->Rect($x3, $y2, 3, 3);
}
}
Upvotes: 1