Reputation: 23
My question is, For example, there are two chapters . The first chapter has one and half page of data in pdf format. When the second chapter starts, it should not start from previous chapters half page, it should get start in next fresh page. These two chapters in while loop. I used the below syntax. Please any one advice me. I am trying since 2 days. Please help me out. I am in starting stage. I am learning tcpdf.
//here is the edited code
while($example = mysqli_fetch_array($sql))
{
//contains some code
$sql_chapter = mysqli_query($dbconn,"SELECT column1, column2, column3 FROM CHAPTER_DETAILS WHERE FORM_NAME='".$example['chapter']."' ");
while($row_chapter=mysqli_fetch_array($sql_chapter))
{
$output = $row_chapter['column1'] ;
$output1 = fnFetchData($row_chapter['column2'],$row_chapter['column3']) ;
$pdf->MultiCell(200, 70, $output, 0, 'L', 0, 0, false);
$pdf->MultiCell(250, 70, $output1, 0, 'L', 0, 0, false);
}
$pdf->AddPage() ;
}
$pdf->lastPage();
$pdf->Output('test.pdf', 'I');
Upvotes: 0
Views: 1711
Reputation: 1289
You should add a new page with AddPage
$pdf->AddPage();
// Reset pointer to the last page
$pdf->lastPage();
// Close and output PDF document
$pdf->Output('test.pdf', 'I');
It should work fine
EDIT
while($example = mysqli_fetch_array($sql))
{
$pdf->startPage() ; // you can also use AddPage();
$sql_chapter = mysqli_query($dbconn,"SELECT column1, column2, column3 FROM CHAPTER_DETAILS WHERE FORM_NAME='".$example['chapter']."' ");
while($row_chapter=mysqli_fetch_array($sql_chapter))
{
$output = $row_chapter['column1'] ;
$output1 = fnFetchData($row_chapter['column2'],$row_chapter['column3']) ;
$pdf->MultiCell(200, 70, $output, 0, 'L', 0, 0, false);
$pdf->MultiCell(250, 70, $output1, 0, 'L', 0, 0, false);
}
$pdf->endPage() ; // only if you use startPage();
}
$pdf->Output('test.pdf', 'I');
Upvotes: 1