2011-01-09 14 views
1

fpdfでテーブルを作成する際に問題があります。FPDFテーブルの作成方法?

誰でもこのページを作るのを手伝ってもいいですか(または少なくとも私にそれを行う方法を教えてください)?

それとも、FPDFテーブルに HTMLテーブルに変換し、ここにコードを配置する方法を示すことができますか?

$person = mysql_fetch_array($result); 

私はこの=(例)とテーブル内に追加するとき、これは機能したい

$pdf->Cell(0,260,''.$person["CA"],'C',0 ,1); --- .$person["CA"] 

できます。

Iは、(データベースへの接続と一緒に)これを持っています誰も私を助ける?

+0

あなたはどのような問題がありますか? – deceze

+0

私はちょうどテーブルを作ることができないようです...例えばfpdfによって提供されたチュートリアルに従うと、countries.txtから抽出されたテキストが表示されますが... $ _POST関数からテキストを抽出したいと考えています.iはこれを持っていますhttp://puertoricohoops.net/invoicestimate/pdf/pdf8.php - テーブル内のテキストは.txtファイルから抽出されますが、私の$ _POST関数でそれらのスポットがいっぱいになります。thnxは役に立ちました – NORM

答えて

6

FPDFは、タイプライターのように動作します。ロービングX、Yポイントが書かれているので、手作業で移動したり、あなたに任せたりできます。

左の巨大な空白が必要かどうかわかりません。もしそうなら、各書き込みの前に$ this-> SetX($ coordinate)を呼び出さなければなりません。 PDFを作成するとき、あなたはこのような何かだろうその後

class InvoicePDF extends FPDF //Create a new class to contain the header/footer/etc. which extends FPDF 
{ 
    public function Header 
    { 
    //Header stuff goes here, like the big Invoice 
     $this->SetY(10); //SetY 10 units down from the top, experiment with distance to get appropriate distance 
     $this->SetFont('Arial','',20); //Set Font to Arial/Helvetica 20 pt font 
     $this->SetTextColor(0,0,0); //Set Text Color to Black; 
     $this->Cell(0,9,"INVOICE",0,0,'R'); //Write the word INVOICE Right aligned in a box the width of the page, will put it at the far right of the page 
    } 

    public function Footer 
    { 
     //any footer stuff goes here 
    } 

    public function FillHeadInfo($info) //$info would be an array of the stuff to fill the small table at the top 
    { 
      $this->SetY(0); //reset the Y to the original, since we moved it down to write INVOICE 
      $this->SetFont('Arial','',12); 
      $this->SetFillColor(224,224,224); //Set background of the cell to be that grey color 
      $this->Cell(20,12,"Order #",1,0,'C',true); //Write a cell 20 wide, 12 high, filled and bordered, with Order # centered inside, last argument 'true' tells it to fill the cell with the color specified 
      $this->Cell(20,12,"Coding",1,0,'C',true); 
      $this->Cell(20,12,"Sales Code",1,1,'C',true); //the 1 before the 'C' instead of 0 in previous lines tells it to move down by the height of the cell after writing this 

      $this->Cell(20,12,$info['ordernum'],1,0,'C'); 
      $this->Cell(20,12,$info['coding'],1,0,'C'); 
      $this->Cell(20,12,$info['salescode'],1,1,'C'); 

      $this->Cell(40,12,"Name & Address",1,0,'C',true); 
      $this->Cell(20,12,"Date",1,1,'C',true); 
      $y = this->GetY(); //Need the current Y value to reset it after the next line, as multicell automatically moves down after write 
      $x = this->GetX(); // Might need the X too 
      $this->MultiCell(40,12,$info['customername'] . "\n" . $info['address'] . "\n" . $info['city'] . ', ' . $info['state'] . ' ' . $info['zip'],1,'L',false); //I assume the customer address info is broken up into multiple different pieces 
      $this->SetY($y); //Reset the write point 
      $this->SetX($x + 40); //Move X to $x + width of last cell 

      $this->Cell(20,36,date("format",strtotime($info['date'])),1,1,'C'); //Might be easier to use $this->Rect() to draw rectangles for address and date and then write the address and date into them without borders using SetX and SetY, if the borders don't line up or whatever 

    } 

    public function fillItems($items) 
    { 
      //You'd build the items list much the same way as above, using a foreach loop or whatever 
      //Could also easily combine this function and the one above 
    } 
} 

あなたはこのような何かを行う必要がありますちなみに

require_once('fpdf.php'); 
require_once('class.invoicepdf.php'); 
//Get whatever info you need to fill the pdf 
$pdf = new InvoicePDF('P','mm','Letter'); 
$pdf->AddPage(); 
$pdf->FillHeadInfo($info); //Could also pass $_POST and rely on the keys of the $_POST array 
$pdf->FillItems($items); 
$pdf->Output('filename.pdf','I'); 

を、私がしようとするのではなく、お勧めしたいです$ _POSTから書き込むには、注文をDBに保存してから、注文IDをスクリプトに渡してリンクと$ _GETを介してpdfを書き込み、スクリプトがDBから情報を取得できるようにします必要な情報のみを選択してください。

+0

thnxが応答しました。コードを試しましたか? PHPはこのエラーを出します:パースエラー:予期しない構文エラー '{'、 '('(パブリック関数ヘッダーの下に)) - 私は私の場合、ビルド項目のリストを理解していません。 "] = address ?? – NORM

+0

私はこのファイルを取得しますか:class.invoicepdf.php – NORM

+0

これはこのエラーを示しています:Parse error:構文エラー、予期しないT_OBJECT_OPERATOR ..行にこれがありました:$ y = this- > GetY(0); $ x = this-> GetX(0);もし私がそれらを取り除くと、私はこれを歪めます:http://puertoricohoops.net/invoicestimate/pdf/pdf9.php - あなたのコードの例では、それは素晴らしいだろう。.. thanx! – NORM

関連する問題