2013-10-25 101 views
0

只需要您對我的代碼的幫助。 我的問題是如何從上一頁獲取表頭並在其餘頁面上訪問它?如果我有大量的數據,我想在每個頁面中也指出表頭。但我不知道該怎麼做。如何使用FPDF庫在每個頁面中顯示錶頭?

下面是建表功能:

function BuildTable($header,$data) { 

      //Colors, line width and bold font 
      $this->SetFillColor(255,255,255); 
      $this->SetTextColor(0); 
      $this->SetDrawColor(0,0,0); 
      $this->SetLineWidth(.3); 
      $this->SetFont('Arial','',7); 

      //Header  
      // make an array for the column widths 

      $this->SetFillColor(0,0,0); 
      $this->SetTextColor(255); 
      $this->SetDrawColor(0,0,0); 
      $this->SetLineWidth(.3); 
      $this->SetFont('','B'); 

      $w = array(15,120,30,30); //CHANGE THIS 
      // send the headers to the PDF document 

      for($i = 0; $i < count($header); $i++) 

       $this->Cell($w[$i],7,$header[$i],1,0,'C',1); 
       $this->Ln(); 

       //Color and font restoration 

       $this->SetFillColor(255,255,230); 
       $this->SetTextColor(0); 
       $this->SetFont(''); 
       $this->SetTextColor(0); 
       $fill = false; // used to alternate row color backgrounds 

      //HERE'S THE PART THAT LOOPS THE DATA 
      foreach($data as $row){ 

       $this->Cell($w[0],4,$row[0],'LR',0,'C',$fill); 
       $this->SetFont(''); 

       $this->Cell($w[1],4,$row[1],'LR',0,'L',$fill); 
       $this->SetFont(''); 

       $this->Cell($w[2],4,$row[2],'LR',0,'R',$fill); 
       $this->SetFont(''); 

       $this->Cell($w[3],4,$row[3],'LR',0,'R',$fill); 
       $this->SetFont(''); 



       $this->Ln(); 
       $fill =! $fill; 
      } 

       $this->Cell(array_sum($w),0,'','T'); 


       $this->Ln(50); 
       $this->Ln(50); 

     } 

下面是呼籲PDF類

foreach($result->result_array() as $row){ 

     $data[] = array($row['item_qty'], 
         $row['itemname'], 
         number_format($row['item_price'],2), 
         number_format($row['total'],2), 

       ); 

    } 


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

    $header = array('QTY','ITEM/DESCRIPTION' , 'UNIT PRICE', 'TOTAL AMOUNT'); 

    $pdf->SetFont('Arial','',8); 
    $pdf->SetFillColor(255,0,0); 

    $pdf->AddPage('l'); 

    $pdf->Ln(); 
    $pdf = new PDF(); 

通過我也有一個頁眉和頁腳功能的方式。 在第一行中,我需要39行,不包括表頭和第二行,其餘行應該是36行。

我該如何計算?我應該在哪裏需要一個計算呢?

請幫助我的人謝謝。

+0

你能告訴我們你的頭功能? – Lithilion

回答

0

根據fpdf教程。

class PDF extends FPDF 
{ 
// Page header 
function Header() 
{ 
    // Logo 
    $this->Image('logo.png',10,6,30); 
    // Arial bold 15 
    $this->SetFont('Arial','B',15); 
    // Move to the right 
    $this->Cell(80); 
    // Title 
    $this->Cell(30,10,'Title',1,0,'C'); 
    // Line break 
    $this->Ln(20); 
} 

// Page footer 
function Footer() 
{ 
    // Position at 1.5 cm from bottom 
    $this->SetY(-15); 
    // Arial italic 8 
    $this->SetFont('Arial','I',8); 
    // Page number 
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
} 
} 

// Instanciation of inherited class 
$pdf = new PDF(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 
$pdf->SetFont('Times','',12); 
for($i=1;$i<=40;$i++) 
    $pdf->Cell(0,10,'Printing line number '.$i,0,1); 
$pdf->Output(); 

reference

相關問題