2016-07-15 42 views
0

我正嘗試從數據庫中的記錄中創建身份證。其中一個人的照片將在左側,並且像下面的屏幕截圖一樣將在側面和下面打印類似的信息。 Screenshot of pdf output showing pagination issue使用Rect FPDF AutoPagination()

使用fpdf單元格我可以使用分頁創建pdf。但爲了上述目的,我認爲使用Rect()將是最好的任務,但是,它不響應autopage中斷。我也意識到在我的代碼中有一個邏輯錯誤,但這是我能得到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; 
}