2016-11-22 5 views
0

FPDF를 통해 PDF로 생성되는 동적 PHP 테이블이 있습니다.FPDF를 사용하여 테이블의 한 열의 너비를 변경하십시오.

어떻게 '이름'열을 다른 열보다 넓게 만들 수 있습니까?

class PDF extends FPDF { 
    function Header() { 
     $this->Image('quote-header.png'); 
     $this->Ln(2); 
    } 

    function Footer() { 
     $this->Image('quote-footer.png'); 
    } 

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

    function BasicTable($header, $data) { 
     foreach($header as $col) 
     $this->Cell(40, 7, $col, 1); 
     $this->Ln(); 
     foreach($data as $row) { 
      foreach($row as $col) 
      $this->Cell(40, 6, $col, 1); 
      $this->Ln(); 
     } 
    } 
} 

$header = array('Product Reference', 'Name', '('. $pound_sign .') Price (excl. VAT)', 'Unit'); 

나는 테이블을 생성하는 유일한 코드라고 확신합니까?

도움이 될 것입니다. 이것은 제가 일하는 회사의 제품 견적 시스템을위한 것이며이 열 너비 문제를 해결하지 않고는 더 이상 진행할 수 없습니다.

테이블은 제품 참조, 이름, 가격 및 단위의 4 개 컬럼으로 구성됩니다. 이름 열이 다른 것보다 넓거나 가능한 경우 제품 이름으로 (자동으로 조정) 필요합니다.

답변

0

Cell 메서드의 첫 번째 매개 변수는 너비입니다. http://www.fpdf.org/en/doc/cell.htm

크기를 두 배로 늘려보십시오.

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(); 

    // This assumes that $row is an int indexed array 
    // E.G looks like array(0 => 'some Product Reference ', 1 => 'Some Name' , 2 =>'Some Price', 3 => 'Some Unit')   
    foreach($data as $row) { 
     foreach($row as $key => $col) { 
      $width = ($key == $nameIndex) ? 80 : 40; 
      $this->Cell($width, 6, $col, 1); 
     } 
     $this->Ln(); 
    } 

} 
+0

이것은 작동하지 않습니다. 내 테이블이 여기 저기에 있습니다. –

+0

@Dan 업데이트 된 코드를 확인하십시오. – bassxzero

+0

충분히 감사드립니다. 어쨌든 테이블 너비가 페이지 여백을 초과하지 못하도록 제한합니까? 왼쪽 여백을 오른쪽 여백과 동일하게 만드는 것이 좋습니다. –