I have 3 arrays ($PSA, $NP and $OP) which I use to generate a pdf. The function I use to generate the pdf is given below. The problem is, all the values in the arrays cannot be contained in one page so there is a need to add page breaks, but when i try to SetAutoPageBreak to TRUE the pdf fail to load. When it is set to False (like in the method) I get only the first page of values(rest is cut-off). Is there a way to manually set page breaks? I could use a condition like:
if($pdf->getPageHeight()-$GetY() < 5) add a page break;
but not sure where to put the code (I'd have to check for the condition before each line is output??)
Thank You!
function generate_pvr($PSA, $NP, $OP, $FROM, $TO){
$heading = 'Test [ From: '.$FROM.' To: '.$TO.' ]';
$border = 0;
$pdf = new TTPDF('P','mm','A4');
$pdf->setMargins(0,0);
$pdf->SetAutoPageBreak(FALSE);
$pdf->AddPage();
$adjust_x = 0;
$adjust_y = 0;
//Heading
$pdf->SetFont('','B',12);
$pdf->setXY( Misc::AdjustXY(30, $adjust_x), Misc::AdjustXY(20, $adjust_y) );
$pdf->Cell(30,15,$heading, $border, 0);
$block_adjust_y = 45;
$block_adjust_x = 40;
//PA entries
foreach( $PSA as $key=>$value ) {
$block_adjust_y = $block_adjust_y + 5;
$pdf->setXY( Misc::AdjustXY($block_adjust_x, $adjust_x), Misc::AdjustXY($block_adjust_y, $adjust_y) );
$pdf->SetFont('','B',12);
$pdf->Cell(45,5, $key, $border, 0, 'L');
$pdf->setXY( Misc::AdjustXY($block_adjust_x + 20, $adjust_x), Misc::AdjustXY($block_adjust_y + 10, $adjust_y) );
$pdf->SetFont('','I',10);
$pdf->Cell(45,5, 'Emp#', $border, 0, 'L');
$pdf->Cell(45,5, 'Employee Name', $border, 0, 'L');
$pdf->Cell(45,5, 'Amount', $border, 0, 'R');
$block_adjust_y = $block_adjust_y + 15;
foreach ($value as $key2=>$value2){
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 5, $adjust_y) );
$pdf->SetFont('','',10);
$pdf->Cell(45,5, $value2['emp_num'], $border, 0, 'L');
$pdf->Cell(45,5, $value2['user_name'], $border, 0, 'L');
$pdf->Cell(45,5, TTi18n::formatNumber( $value2['amount'] ), $border, 0, 'R');
$sumpsa = $sumpsa + $value2['amount'];
$block_adjust_y = $block_adjust_y + 5;
}
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 5, $adjust_y) );
$pdf->SetFont('','B',10);
$pdf->Cell(90,5, 'Total', $border, 0, 'C');
$pdf->Cell(45,5, TTi18n::formatNumber( $sumpsa ), $border, 0, 'R');
$sumpsa = 0;
$block_adjust_y = $block_adjust_y + 10;
}
//NP entries
$pdf->setXY( Misc::AdjustXY($block_adjust_x, $adjust_x), Misc::AdjustXY($block_adjust_y + 5, $adjust_y) );
$pdf->SetFont('','B',12);
$pdf->Cell(45,5, 'NP', $border, 0, 'L');
$pdf->setXY( Misc::AdjustXY($block_adjust_x + 20, $adjust_x), Misc::AdjustXY($block_adjust_y + 15, $adjust_y) );
$pdf->SetFont('','I',10);
$pdf->Cell(45,5, 'Emp#', $border, 0, 'L');
$pdf->Cell(45,5, 'Employee Name', $border, 0, 'L');
$pdf->Cell(45,5, 'Amount', $border, 0, 'R');
$block_adjust_y = $block_adjust_y + 15;
foreach ($NP as $keynp => $valuenp){
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 10, $adjust_y) );
$pdf->SetFont('','',10);
$pdf->Cell(45,5, $valuenp['employee_number'], $border, 0, 'L');
$pdf->Cell(45,5, $valuenp['user_name'], $border, 0, 'L');
$pdf->Cell(45,5, TTi18n::formatNumber( $valuenp['amount'] ), $border, 0, 'R');
$sum_nopay = $sum_nopay + $valuenp['amount'];
$block_adjust_y = $block_adjust_y + 5;
}
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 10, $adjust_y) );
$pdf->SetFont('','B',10);
$pdf->Cell(90,5, 'Variation Total', $border, 0, 'C');
$pdf->Cell(45,5, TTi18n::formatNumber( $sum_nopay ), $border, 0, 'R');
$sum_nopay = 0;
$block_adjust_y = $block_adjust_y + 10;
//OP entries
$pdf->setXY( Misc::AdjustXY($block_adjust_x, $adjust_x), Misc::AdjustXY($block_adjust_y + 5, $adjust_y) );
$pdf->SetFont('','B',12);
$pdf->Cell(45,5, 'Over Pay', $border, 0, 'L');
$pdf->setXY( Misc::AdjustXY($block_adjust_x + 20, $adjust_x), Misc::AdjustXY($block_adjust_y + 15, $adjust_y) );
$pdf->SetFont('','I',10);
$pdf->Cell(45,5, 'Emp#', $border, 0, 'L');
$pdf->Cell(45,5, 'Employee Name', $border, 0, 'L');
$pdf->Cell(45,5, 'Amount', $border, 0, 'R');
$block_adjust_y = $block_adjust_y + 15;
foreach ($OP as $keyop => $valueop){
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 10, $adjust_y) );
$pdf->SetFont('','',10);
$pdf->Cell(45,5, $valueop['employee_number'], $border, 0, 'L');
$pdf->Cell(45,5, $valueop['user_name'], $border, 0, 'L');
$pdf->Cell(45,5, TTi18n::formatNumber( $valueop['amount'] ), $border, 0, 'R');
$sum_overpay = $sum_overpay + $valueop['amount'];
$block_adjust_y = $block_adjust_y + 5;
}
$pdf->setXY( Misc::AdjustXY($block_adjust_x+20, $adjust_x), Misc::AdjustXY($block_adjust_y + 10, $adjust_y) );
$pdf->SetFont('','B',10);
$pdf->Cell(90,5, 'Variation Total', $border, 0, 'C');
$pdf->Cell(45,5, TTi18n::formatNumber( $sum_overpay ), $border, 0, 'R');
$sum_overpay = 0;
$block_adjust_y = $block_adjust_y + 10;
return $pdf->Output('','S');
}