2016-08-11 3 views
1

私はFPDFライブラリを使用して、自分のデータベースの内容をPDFに変換しています。ただし、pdfの最初のページがいっぱいになると、次のページにページを設定できません。これで内容が間違って表示されてしまいます。新しいページを追加するにはどうしたらいいですか?誰でも?FPDFに次のページ区切りを追加するには

<?php 
ob_start(); 
require('fpdf/fpdf.php'); 

//Select the Products you want to show in your PDF file 
$result= mysqli_query($conn, "SELECT * FROM customer"); 

$number_of_products = mysqli_num_rows($result); 

//Initialize the columns and the total 
$column_id = ""; 
$column_name = ""; 
$column_trans_id = ""; 
$column_amount = ""; 

//For each row, add the field to the corresponding column 
while($row = mysqli_fetch_array($result)) 
{ 
    $id = $row["id"]; 
    $name = $row["name"]; 
    $trans_id = substr($row["trans_id"],0,20); 
    $amount = $row["amount"]; 

    $column_id = $column_id.$id."\n"; 
    $column_name = $column_name.$name."\n"; 
    $column_trans_id = $column_trans_id.$trans_id."\n"; 
    $column_amount = $column_amount.$amount."\n"; 

} 
mysqli_close(); 

//Create a new PDF file 
$pdf=new FPDF(); 
$pdf->AddPage(); 
$p->SetAutoPageBreak(false); 
//Fields Name position 
$Y_Fields_Name_position = 20; 
//Table position, under Fields Name 
$Y_Table_Position = 26; 

//First create each Field Name 
//Gray color filling each Field Name box 
$pdf->SetFillColor(232,232,232); 
//Bold Font for Field Name 
$pdf->SetFont('Arial','B',6); 
$pdf->SetY($Y_Fields_Name_position); 
$pdf->SetX(0); 
$pdf->Cell(10,6,'ID',1,0,'L',1); 
$pdf->SetX(10); 
$pdf->Cell(40,6,'NAME',1,0,'L',1); 
$pdf->SetX(50); 
$pdf->Cell(15,6,'AMOUNT',1,0,'L',1); 
$pdf->SetX(65); 

$pdf->Ln(); 

//Now show the columns 
$pdf->SetFont('Arial','',5); 
$pdf->SetY($Y_Table_Position); 
$pdf->SetX(0); 
$pdf->MultiCell(10,6,$column_id,1); 
$pdf->SetY($Y_Table_Position); 
$pdf->SetX(10); 
$pdf->MultiCell(40,6,$column_name,1); 
$pdf->SetY($Y_Table_Position); 
$pdf->SetX(50); 
$pdf->MultiCell(15,6,$column_amount,1); 
$pdf->SetY($Y_Table_Position); 
$pdf->SetX(65); 

//Create lines (boxes) for each ROW (Product) 
//If you don't use the following code, you don't create the lines separating each row 
$i = 0; 
$pdf->SetY($Y_Table_Position); 
while ($i < $number_of_products) 
{ 
    $pdf->SetX(0); 
    $pdf->MultiCell(65,6,'',1); 
    $i = $i +1; 
} 
ob_end_clean(); 
$pdf->Output(); 
ob_end_flush(); 
?> 
+0

あなたはそれを知っていますか、自動改ページを無効に? – KhorneHoly

+0

@KhorneHoly '$ p-> SetAutoPageBreak(true);' $ p-> SetAutoPageBreak(false);に設定すると何も出力せず、少なくともページ区切りなしでも出力が得られます! –

答えて

-1
<?php 
    require('fpdf.php'); 
    $pdf = new FPDF('P','mm','A5'); 
    $pdf->AddPage('P'); 
    $pdf->SetDisplayMode(real,'default'); 
    $pdf->SetFont('Arial','',10); 
    $txt = file_get_contents('comments.txt', true); 
    $pages = explode('~', $txt); 
    foreach ($pages as $page) { 
     $pdf->Write(8, $page); 
     $pdf->AddPage(); 
    } 
    $pdf->Output(); 
?> 
+0

私のコードに基づいた説明は、私だけでなく他の誰かを助けるでしょう。親切に.. –

関連する問題