首頁 php教程 PHP开发 php FPDF類別庫應用實作程式碼

php FPDF類別庫應用實作程式碼

Dec 14, 2016 pm 12:00 PM
fpdf

require('chinese.php'); 
class PDF extends PDF_Chinese 

function Header() //設定頁眉 

$this->SetFont(10)'
$this->Write(10,'XX公司產品名錄'); 
$this->Ln(20); //換行 

function Footer() //設定頁腳 

$-this>SetY (-15); 
$this->SetFont('GB','',10); 
$this->Cell(0,10,'第'.$this->PageNo().'頁');

}

$conn = mysql_connect("localhost", "root", ""); //連接資料庫

mysql_select_db("product", $conn); //執行FROM product ORDER BY prod_id"; 
$rs_prod = mysql_query($query_rs_prod, $conn) or die(mysql_error()); 
$row_rs_prod = my_fetch_assoc($a_prod); d);

$ pdf=new PDF(); //建立新的FPDF物件 

$pdf->AddGBFont(); //設定中文字體 

$pdf->Open(); //開始建立PDF 
$pdf->AddPage() ; //增加一頁

$pdf->SetFont('GB','',10); //設定字型樣式

$header=array('產品編號','產品名稱','產品類型' ,'產品單價'); //設定表頭 

$width=array(20,80,40,20); //設定每列寬度


for($i=0;$i$pdf->Cell($width[$i],6,$header[$i],1); 

$pdf->Ln();

do //循環輸出表體 

$pdf->Cell($width[0],6,$row_rs_prod['prod_id'],1); 
$pdf->Cell($width[1],6,$row_rs_prod[ 'prod_name'],1); 
$pdf->Cell($width[2],6,$row_rs_prod['prod_type'],1); 
$pdf->Cell($width[3],6,$ row_rs_prod['prod_price'],1); 
$pdf->Ln(); 
} while ($row_rs_prod = mysql_fetch_assoc($rs_prod));

$pdf->Output("produ.M. //下載PDF檔 

?>


程式碼如下:

define('FPDF_FONTPATH','font/'); //定義font資料夾所在路徑 
require_once('fpdf/fpdf.php') ; //包含fpdf類別庫檔案 
$pdf=new FPDF('P', 'mm', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$ pdf->Open(); //開始建立PDF 
$pdf->AddPage(); //增加一頁 
$pdf->SetFont('Courier','I',20); //設定字體樣式 
$pdf->Cell(0,0,'Hello World!'); //增加一個儲存格 
$pdf->Output(); //輸出PDF到瀏覽器 
?>

程式碼如下:

define('FPDF_FONTPATH','font/'); //定義font資料夾所在路徑 
require_once('fpdf/fpdf.php'); //包含fpdf類別庫檔案 
$pdf=new FPDF(' P', 'mm', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$pdf->Open(); //開始建立PDF 
$pdf- >AddPage(); //增加一頁 
$pdf->SetFont('Courier','I',20); //設定字型 
$pdf->Image('sight.jpg',20,20, 0,0); //增加一張圖片,檔案名稱為sight.jpg 
$pdf->Output(); //輸出PDF到瀏覽器 
?>

程式碼如下:

define(
程式碼如下:
define( 'FPDF_FONTPATH','font/'); //定義font資料夾所在路徑 
require_once('fpdf/fpdf.php'); //包含fpdf類別庫檔案 
$pdf=new FPDF('P', 'mm ', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$pdf->Open(); //開始建立PDF 
$pdf->AddPage(); //增加一頁 
$pdf->SetFont('Courier','I',20); //設定字型 
$pdf->Cell(60,10,'Hello World!',1); //增加一個儲存格邊框為1 
$pdf->Output(); //輸出PDF到瀏覽器 

?>



 程式碼如下:
define('FPDF_FONTPATH','font/'); / /定義font資料夾所在路徑 
require_once('fpdf/fpdf.php'); //包含fpdf類別庫檔案 
$pdf=new FPDF('P', 'mm', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$pdf->Open(); //開始建立PDF 

$pdf->AddPage(); //增加一頁

$pdf-> SetFont('Arial','',14); //設定字體樣式🎜

$header=array('Name','Age','Sex','Salary'); //設定表頭 
$data=array(); //設定表體 
$data[0] = array( 'Simon','24','Male','5,000.00'); 
$data[1] = array('Elaine','25','Female','6,000.00'); 
$data[2] = array('Susan','25','Female','7,000.00'); 
$data[3] = array('David','26','Male','8,000.00');

$width= array(40,40,40,40); //設定每列寬度

for($i=0;$i$pdf->Cell ($width[$i],6,$header[$i],1); 
$pdf->Ln();

foreach($data as $row) //迴圈輸出表體 

$pdf ->Cell($width[0],6,$row[0],1); 
$pdf->Cell($width[1],6,$row[1],1); 
$pdf-> Cell($width[2],6,$row[2],1); 
$pdf->Cell($width[3],6,$row[3],1); 
$pdf->Ln( ); 
}

$pdf->Output(); //輸出PDF到瀏覽器 
?>


 程式碼如下:
define('FPDF_FONTPATH', CATH'); font資料夾所在路徑 
require_once('fpdf/fpdf.php'); //包含fpdf類別庫檔案 
$pdf=new FPDF('P', 'mm', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$pdf->Open(); //開始建立PDF 
$pdf->AddPage(); //增加一頁 
$pdf->SetFont(' Courier','I',20); //設定字體樣式 
$pdf->Cell(0,0,'你好,FPDF'); //增加一個儲存格並輸出中文 
$pdf->Output( ); //輸出PDF到瀏覽器 
?>


程式碼如下:
require('chinese.php'); 
class PDF extends PDF_Chinese 


.

$this->SetFont('GB','',10); 
$this->Write(10,'FPDF中文測驗'); 
$this->Ln(20); 

}


$this->Ln(20); 
}

function Footer() //設定頁腳 

$this->SetY(-15); 

$this->SetFont('GB','',10); 

$this->Cell(0,10, '第'.$this->PageNo().'頁'); 

}

$pdf=new PDF(); //建立PDF文件 
$pdf->AddGBFont(); 
$pdf-> Open(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 

$pdf->SetFont('GB','I',20); 

$pdf->Cell(0,10 ,'你好,FPDF'); //輸出一段中文 
$pdf->Output(); 
?>

代碼如下:

$conn = mysql_connect("localhost", "root", ""); //連接資料庫 
$colname_rs_article = $_GET['id']; //取得參數id

mysql_select_db("cms", $conn); //執行SQL 

$query_rs_article = sprintf("SELECT * FROM articles WHERE article_id = %s", $colname_rs_article); 

$rs_article = mysql_query($query_rs_article, $conn) or die(mysql_error()); ws_rs_article = mysql_num_rows($ rs_article);

function conv($Text) //對回傳文字處理 

$Text=htmlspecialchars($Text); //轉換HTML關鍵字元 
$Text=nl2br($Text); //轉換換行符 
return $Text; 

?> 

 

| 下載PDF文件

 


 🎜

🎜


程式碼如下:
require('chinese.php'); 
class PDF extends PDF_Chinese 

function Header() //設定頁眉'Y🎓 ',10); 
$this->Write(10,'文章系統- XX網站'); 
$this->Ln(20); //換行 

function Footer() //設定頁腳


$this->SetY(-15); 
$this->SetFont('GB','',10); 
$this->Cell(0,10,'第'.$this->PageNo() .'頁'); 


//主程式開始 
$conn = mysql_connect("localhost", "root", ""); //連結資料庫 
$colname_rs_article = $root", ""); //連結資料庫 
$colname_rs_article = $_GET['id'id']; //取得參數id

mysql_select_db("cms", $conn); //執行SQL 
$query_rs_article = sprintf("SELECT * FROM articles WHERE article_id = %s", $colname_rs_article); query_rs_article, $conn) or die(mysql_error()); 
$row_rs_article = mysql_fetch_assoc($rs_article); 
$totalRows_rs_article = my_article); 
$totalRows_rs_article = my_article); 
$totalRows_rs_article = my_article); 
$pdf->AddGBFont(); 
$pdf->Open(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 
$pdf->SetFont('GB','B', 20); 
$pdf->Cell(0,10,$row_rs_article['title']); //輸出文章標題 
$pdf->Ln(); //換行 
$pdf->SetFont('GB' ,'',10); 
$pdf->Cell(0,10,$row_rs_article['author']); //輸出文章作者 
$pdf->Ln(); 
$pdf->SetFont('GB ','',12); 
$content = $row_rs_article['content']; 
while($content != "") //將文章內容循環逐頁寫入PDF 

$length = strlen($ content); //取得文章長度 
$output = substr($content, 0, 1024); //取得本頁輸出內容,每1024個字元為1頁 
$pdf->Cell(0,10,$output ); //輸出文章內容 
$content = substr($content, 1024, $length); //取得剩餘未輸出內容 
$pdf->AddPage(); //換頁 

$pdf->Output ($row_rs_article['title'].".pdf", true); //輸出PDF文件,文件名稱為文章標題 
?>

程式碼如下:
define('FPDF_FONTPATH','font /'); //定義font資料夾所在路徑 
require_once('fpdf/fpdf.php'); //包含fpdf類別庫檔案

class PDF extends FPDF 


function Header() //設定頁眉 

function Header() //設定頁眉 🠎 { 
$this->SetFont('Arial','B',15); //設定頁眉字體 
$this->Cell(80); //行動儲存格 
$this->Cell(30,10 ,'Title'); //寫入頁眉文字 
$this->Ln(20); //換行 
}

function Footer() //設定頁腳 

$this->SetY(-15 ); //設定頁腳所在位置 
$this->SetFont('Arial','I',8); //設定頁腳字體 
$this->Cell(0,10,'Page - '.$ this->PageNo()); //輸出目前頁碼作為頁腳內容 

}

$pdf=new PDF('P', 'mm', 'A4'); //建立新的FPDF對象,垂直放紙,單位為毫米,紙張大小A4 
$pdf->Open(); //開始建立PDF 
$pdf->AddPage(); //增加一頁 
$pdf->SetFont('Courier' ,'I',20); //設定字型樣式 
$pdf->Cell(0,0,'Hello World!'); //增加一個儲存格 
$pdf->Output(); //輸出PDF到瀏覽器 
?>

以上就是php FPDF類庫應用程式碼希望可以幫助到大家,更多相關內容請關注PHP中文網(www.php.cn)!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)