2015-09-28 43 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

奧克我看到的問題,我將編輯腳本 –

相關問題