最近項目中需要用到PHP創建PDF文檔,初步篩選決定使用FPDF這個純PHP庫來實現,類似的還有TCPDF等,有機會也可以試試。
FPDF官網:http://www.fpdf.org
logo是個可愛小象
:)
截至17.11.30,
官網最新的類庫版本爲v1.81:http://www.fpdf.org/en/dl.php?v=181&f=zip
中文版手冊版本爲v1.52:http://www.fpdf.org/en/dl.php?id=72
將FPDF類庫引入到本地後,先來看個例子:
<?php
//引用文件
require('fpdf181/fpdf.php');
$pdf=new FPDF('L','mm','A4');
//$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','B',17);
$pdf->Cell(0,10,'Hello World!','1');
$pdf->Output();
?>
運行後,在瀏覽器端將輸出一個PDF文件這裏簡單解釋下用到的幾個函數:
- FPDF([string orientation [, string unit [, mixed format]]])
- AddPage([string orientation])
- SetFont(string family [, string style [, float size]])
- Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, int fill [, mixed link]]]]]]])
- string Output([string name [, string dest]])