FPDF 是一個 PHP 物件類別,可以由 PHP 直接動態產生PDF 檔,而不需要透過 PDFlib 函式庫(PDFlib商用要付費)。
特色
- 自定義頁眉及頁腳
- 自動換行
- 支持圖像插入(JPEG/PNG)
- 支持顏色
- 支持插入鏈接
- 支持TrueType, Type1和編碼
- 支持壓縮頁面 版本為1.6
官方網站:
http://www.fpdf.org中文文件:
http://twpug.net/docs/fpdf152/下載下來後,只要引入就可以使用。
以下是一簡單範例及說明:
02 | define('FPDF_FONTPATH',"fpdf/font/"); |
04 | require("fpdf/fpdf.php"); |
07 | $pdf=new FPDF('P','mm','A4'); |
09 | $pdf->SetTitle("Test Title"); |
10 | $pdf->SetAuthor("Test Author"); |
13 | $pdf->SetFont('Arial','B',16); |
14 | $pdf->SetTextColor(153, 153, 153); |
15 | $pdf->Cell(40,10,'Hello World!'); |
19 | $pdf->SetDrawColor(204, 204, 204); |
20 | $pdf->SetLineWidth(0.4); |
21 | $pdf->Line(10, 30, 200, 30); |
23 | $pdf->SetFillColor(102, 102, 102); |
24 | $pdf->SetFont('Arial','',9); |
25 | $pdf->SetTextColor(255, 255, 255); |
26 | $pdf->Cell(65, 10, "test content", 1, 0, 'C', 1); |
30 | $pdf->SetFont('Arial','I',8); |
31 | $pdf->Cell(0,10,$pdf->PageNo(),0,0,'C'); |
33 | $filename = "test.pdf"; |
36 | header("Content-type:application/pdf"); |
37 | header("Content-Disposition:attachment;filename=$filename"); |
39 | header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); |
40 | header("Pragma: public"); |
42 | $pdf->Output("test.pdf", 'D'); |
轉貼置 :http://mrbignose.blogspot.com/2010/02/phpfpdfpdf.html