php生成pdf文件

2021-07-30 04:15:49 字數 2460 閱讀 7973

實際工作中,我們要使用php動態的建立pdf文件,目前有許多開源的php建立pdf的類庫,今天我給大家來介紹一款優秀的pdf庫,它就是tcpdf,tcpdf是乙個用於快速生成pdf檔案的php5函式包。tcpdf基於fpdf進行擴充套件和改進,增強了實用功能。

特性 tcpdf具有以下特性:

1、支援頁面頁尾;

2、支援html標籤**;

3、支援jpg/png/gif/svg圖形影象;

4、支援**;

5、支援中文字元;(有些pdf類不支援中文或者處理中文相當麻煩)

6、自動分頁,自動頁碼,等等。

如何使用

1、require_once匯入tcpdf.php檔案及相關配置資訊;

2、例項化tcpdf;

3、設定pdf文件的格式,包括文件資訊、頁首、頁尾、字型、外間距、邊框、分頁等;

4、匯入pdf文件的內容,可以是單行或多行簡單字串,也可以html格式的字串等;

5、輸出pdf文件。

**示例:

require_once('tcpdf.php');  //例項化

$pdf = new tcpdf('p', 'mm', 'a4', true, 'utf-8', false); 

// 設定文件資訊

$pdf->setcreator('helloweba');  $

pdf->setauthor('yueguangguang');  $

pdf->settitle('welcome to helloweba.com!');  $

pdf->setsubject('tcpdf tutorial');  $

pdf->setkeywords('tcpdf, pdf, php'); 

// 設定頁首和頁尾資訊

$pdf->setheaderdata('logo.png', 30, 'helloweba.com', '致力於web前端技術在中國的應用',  

array(0,64,255), array(0,64,128));  $

pdf->setfooterdata(array(0,64,0), array(0,64,128)); 

// 設定頁首和頁尾字型

$pdf->setheaderfont(array('stsongstdlight', '', '10'));  $

pdf->setfooterfont(array('helvetica', '', '8')); 

// 設定預設等寬字型

$pdf->setdefaultmonospacedfont('courier'); 

// 設定間距

$pdf->setmargins(15, 27, 15);  $

pdf->setheadermargin(5);  $

pdf->setfootermargin(10); 

// 設定分頁

$pdf->setautopagebreak(true, 25); 

// set image scale factor

$pdf->setimagescale(1.25); 

// set default font subsetting mode

$pdf->setfontsubsetting(true); 

//設定字型

$pdf->setfont('stsongstdlight', '', 14); 

$pdf->addpage(); 

$str1 = '歡迎來到helloweba.com'; 

$pdf->write(0,$

str1,'', 0, 'l', true, 0, false, false, 0); 

//輸出pdf

$pdf->output('t.pdf', 'i');

其他php生成pdf的常用類

fpdf

html2pdf

html2pdf能夠把乙個html文字轉換成乙個印表機友好的pdf檔案。這個php指令碼構建在fpdf php指令碼之上。

tcpdf

tcpdf是乙個用於快速生成pdf檔案的php5函式包。tcpdf基於fpdf進行擴充套件和改進。支援utf-8,unicode,html和xhtml。

html2ps

html2ps 能夠把帶有,複雜**(包含rowspan/colspan) ,layer/div和css樣式的html轉換成postscript與pdf。 html2ps對css2.1支援非常好,並且很好地相容不正確的hmtl。它甚至能夠轉換幾乎是採用css設計的**如msn.com。

html_topdf

html_topdf能夠把任何html文件轉換成在任何平台和印表機下介面格式都一樣的pdf文件。它包括支援轉換,使用樣式表來定製pdf檔案和錯誤處理。

cpdfwriter

cpdfwriter是乙個能夠輸出pdf文件的php5 class。基於tcpdf,fpdf和其它相關指令碼。

dompdf

使用PHP生成PDF文件

實際工作中,我們要使用php動態的建立pdf文件,目前有許多開源的php建立pdf的類庫,今天我給大家來介紹一款優秀的pdf庫,它就是tcpdf,tcpdf是乙個用於快速生成pdf檔案的php5函式包。tcpdf基於fpdf進行擴充套件和改進,增強了實用功能。特性tcpdf具有以下特性 1 支援頁面...

使用PHP生成PDF文件

實際工作中,我們要使用php動態的建立pdf文件,目前有許多開源的php建立pdf的類庫,今天我給大家來介紹一款優秀的pdf庫,它就是tcpdf,tcpdf是乙個用於快速生成pdf檔案的php5函式包。tcpdf基於fpdf進行擴充套件和改進,增強了實用功能。檢視演示 特性tcpdf具有以下特性 1...

itext生成pdf文件

包 交易金額 datamap.put jine order.getorderprojiectmoney datamap.put jinedaxie stringutil.trans2rmb order.getorderprojiectmoney datamap.put daozhangshijian...