2015-09-28 42 views
0

我的问题是,例如,有两章。第一章有pdf格式的一页半页数据。第二章开始时,不应该从前一章半页开始,它应该在下一个新页面开始。 while循环中的这两章。我使用了下面的语法。请任何人建议我。我尝试了2天。请帮助我。我正处于起步阶段。我正在学习tcpdf。如何在第一页和第二页后在tcpdf中生成新页面

//这里是编辑的代码

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'); 

回答

1

您应该添加一个新的页面,AddPage

$pdf->AddPage(); 

// Reset pointer to the last page 
$pdf->lastPage(); 

// Close and output PDF document 
$pdf->Output('test.pdf', 'I'); 

它应该工作正常

编辑

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'); 
+0

感谢ü为了您的回应。但我没有得到正确的答案..我包括代码..请检查出来,让我知道我犯了什么错误.. –

+0

你应该把你的AddPage();在循环内部,否则它会先循环并在此之后添加页面。我不知道这是否意图 –

+0

奥克我看到的问题,我将编辑脚本 –

相关问题