2016-11-23 1 views
2

FPDF와 Cell 메서드를 사용하여 테이블을 만들었습니다. 이 기능은 훌륭했지만 각 열의 너비가 일정했기 때문에 테이블이 오른쪽 페이지 여백을 초과하고 제품 이름이 제품 가격과 겹치므로 여러 가지 문제가 발생하여 읽을 수 없습니다.FPDF MultiCell은 각 열마다 한 줄씩 작성합니다.

Google 및 스택에서 문제를 조사한 후 코드를 MultiCell로 변경했지만 각 열에 이제 전체 행이 있습니다. Cell과 MultiCell 테이블의 그림을 제공하고 각 메소드에 대한 코드도 제공했습니다.

여러분 중 한 명이 도움을 주시기 바랍니다.

감사합니다.

멀티 셀 : 는 enter image description here

셀 :

class PDF extends FPDF {  
    function LoadData($file) { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
     $data[] = explode(';', trim($line)); 
     return $data; 
    } 

    function BasicTable($header, $data) { 
     $nameIndex = array_search ('Name', $header);  

     foreach($header as $key => $col) { 
      $width = ($key == $nameIndex) ? 80 : 40; 
      $this->Cell($width, 7, $col, 1);    
     } 

     $this->Ln(); 

     foreach($data as $row) { 
      foreach($row as $key => $col) { 
       $width = ($key == $nameIndex) ? 80 : 40; 
       $this->Cell($width, 6, $col, 1); 
      } 

      $this->Ln(); 
     } 
    } 
} 

코드 멀티 셀 방법 : 셀 방법 이 enter image description here

코드

class PDF extends FPDF {  
    function LoadData($file) { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
     $data[] = explode(';', trim($line)); 
     return $data; 
    } 

    function BasicTable($header, $data) { 
     $nameIndex = array_search ('Name', $header);  

     foreach($header as $key => $col) { 
      $this->MultiCell($width, 7, $col, 1);    
     } 

     $this->Ln(); 

     foreach($data as $row) { 
      foreach($row as $key => $col) { 
       $this->MultiCell($width, 6, $col, 1); 
      } 

      $this->Ln(); 
     } 
    } 
} 

답변

관련 문제