2016-10-04 3 views
2

이 종류의 pdf를 생성하려고하는데 첫 페이지에서 모든 것이 정상입니다.FPDF PHP에서 SetXY()를 사용하여 새 페이지에서 셀 시작

enter image description here

그러나 때 페이지 나누기 새 페이지에 Cell() 시작 I 루프 더 다음 23 번을 보이는 경우.

enter image description here

나는 첫 페이지처럼 표시하려면이 셀() 할 수 있습니다. 모든 솔루션은 높게 평가 될 것이다

class PDF extends FPDF { 
    public $hPosX; 
    public $hPosY; 
    function FancyTable() { 
     $this->SetFillColor(255,0,0); 
     $this->SetTextColor(255,0,0); 
     $this->SetDrawColor(128,0,0); 
     $this->SetLineWidth(.3); 
     $this->SetFont('','B'); 

     $this->headerTable(); 
    } 

    public function headerTable(){ 
     $this->hPosX = 15; 
     $this->hPosY = 3; 
     $this->SetFillColor(255,0,0); 
     $this->SetTextColor(255); 
     $this->SetDrawColor(128,0,0); 
     $this->SetLineWidth(.3); 
     $this->SetFont('','B'); 
     for($i=0; $i<30;$i++){ 
      if($this->GetX() > 160){ 
       $this->hPosX = 15; 
       $this->hPosY += 35; 
      } 

      $this->SetXY($this->hPosX,$this->hPosY); 
      $this->Cell(50,5,'Header'.$i,1,0,'L',true); 

      $this->hPosX += 55; 
     } 
    } 
} 




$pdf = new PDF(); 
$pdf->SetTopMargin(10); 
$pdf->SetFont('Arial','',14); 
$pdf->AddPage(); 
$pdf->FancyTable(); 
$pdf->Output(); 

:

여기 내 코드입니다.

답변

0

해결되었습니다. GetY()가 현재 페이지보다 크고 새 페이지를 추가하고 hPosY 변수를 기본값으로 다시 설정하면 페이지 나누기를 중단해야했습니다.

또한 GetX()가 160보다 크고 hPosX를 기본값으로 재설정 했으므로 페이지의 마지막 요소가 페이지에 맞고 새 페이지에서 제대로 시작됩니다.

public function headerTable(){ 
$this->hPosX = 15; 
$this->hPosY = 3; 
$this->SetFillColor(255,0,0); 
$this->SetTextColor(255); 
$this->SetDrawColor(128,0,0); 
$this->SetLineWidth(.3); 
$this->SetFont('','B'); 
for($i=0; $i<30;$i++){ 
if($this->GetX() > 160){ 
$this->hPosX = 15; 
$this->hPosY += 35; 
} 

$this->SetXY($this->hPosX,$this->hPosY); 
$this->Cell(50,5,'Header'.$i,1,0,'L',true); 

$this->hPosX += 55; 

if($this->GetY() > 240 && $this->GetX() > 160){ 
$this->SetAutoPageBreak(false); 
$this->AddPage(); 
$this->hPosX = 15; 
$this->hPosY = 3; 
} 
} 

} 
: 여기

'는 headerTable() 변형 방법의 코드