I'm trying to generate this kind of pdf and in the first page everything is ok.
But when I loop more then 23 times it looks the Cell()
starts in the new page when page breaks.
I want this Cell() to display like in first page.
Here is my code:
class PDF extends FPDF {
public $hPosX;
public $hPosY;
function FancyTable() {
$this->SetFillColor(255,0,0);
$this->SetTextColor(255,0,0);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
$this->headerTable();
}
public function headerTable(){
$this->hPosX = 15;
$this->hPosY = 3;
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
for($i=0; $i<30;$i++){
if($this->GetX() > 160){
$this->hPosX = 15;
$this->hPosY += 35;
}
$this->SetXY($this->hPosX,$this->hPosY);
$this->Cell(50,5,'Header'.$i,1,0,'L',true);
$this->hPosX += 55;
}
}
}
$pdf = new PDF();
$pdf->SetTopMargin(10);
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->FancyTable();
$pdf->Output();
Any solution will be highly appreciated.
Solved. Just I had to stop page break if the GetY() is greater than current page, add new page, and reset hPosY variable to his default value.
i have also checked if GetX() is greater than 160 and reset hPosX to his default value so last elements on page will fit the page and starts properly on new page.
Here is the code of modified method 'headerTable()':
public function headerTable(){
$this->hPosX = 15;
$this->hPosY = 3;
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
for($i=0; $i<30;$i++){
if($this->GetX() > 160){
$this->hPosX = 15;
$this->hPosY += 35;
}
$this->SetXY($this->hPosX,$this->hPosY);
$this->Cell(50,5,'Header'.$i,1,0,'L',true);
$this->hPosX += 55;
if($this->GetY() > 240 && $this->GetX() > 160){
$this->SetAutoPageBreak(false);
$this->AddPage();
$this->hPosX = 15;
$this->hPosY = 3;
}
}
}