2016-07-15 6 views
0

データベースのレコードからIDカードを作成しようとしています。人の写真が左側にあり、以下のスクリーンショットのように、側面と下に情報が表示されます。 Screenshot of pdf output showing pagination issueFPDFオートペインティングRect()

fpdfセルを使用して、ページングを使用してpdfsを作成することができました。しかし、私はRect()を使うのがこの作業のために最適だと思ったが、オートページブレークには反応しなかった。私は自分のコードに論理的なエラーがあることも認識していますが、これが3列の出力を得ることができる唯一の方法です。私は以下のコードの誤りを訂正する助けを得ることをうれしく思います。ありがとうございました!

class PDF extends FPDF { 
    function Header(){ 
     $this->SetFont('Arial', '', 10); 
     $this->Cell(18, 10, '', 0); 
     $this->SetFont('Arial', '', 9); 
     $this->Cell(35, 10, 'Date: '.date('d-m-Y').'', 0); 
     $this->Ln(12); 
     $this->SetFont('Arial', 'B', 11); 
     $this->Cell(70, 8, '', 0); 
     $this->Cell(100, 8, 'LIST', 0); 
     $this->Ln(13); 
    } 

    function Footer(){ 
     $this->SetY(-15); 
     $this->SetFont('Arial','I',8); 
     $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
    } 
} 

$pdf = new PDF(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 


$staff = mysql_query("SELECT * FROM staff"); 
$item = 0; 
$width = 60; 
$height = 40; 
$x = 15; 
$y = 35; 
$margin = 2; 
while($a_staff = mysql_fetch_array($staff)){ 
    $item = $item+1; 
    for($i = 0; $i < 3; $i++){ 
     $pdf->Rect($x, $y, $width, $height, 'D'); 
     $pdf->Image('images.gif' , $x+$margin ,$y+$margin, 25 , 25); 
     $x = ($x + $width + $margin); 
    } 
    $y = $y + $height + $margin; 
    $x = 15; 
} 

$pdf->Output("report.pdf", "I"); 
?> 
+0

あなたはPHPの 'mysql_ *'関数を使用して学習したり、新しいコードを書くのは避けるべきです。それらは最新バージョンで削除されており、あなたのコードは将来は機能しません。なぜPHPのmysql_ *関数を使うべきではないのですか?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)を読んでください。それらを何に置き換えるか。 –

答えて

0

追加するコンテンツの開始Y座標と高さを知っているので、手動でページネーションを行うことができます。

$y = $y + $height + $margin;した後、追加:

// replace 20 with whatever margin you need at the bottom of the page 
if ($y + $height > $pdf->h - 20) { 
    $pdf->AddPage(); 
    $y = 35; 
}