欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php FPDF類庫(kù)應(yīng)用實(shí)現(xiàn)代碼

 更新時(shí)間:2009年03月20日 00:04:45   作者:  
php FPDF類庫(kù)應(yīng)用實(shí)現(xiàn)代碼
復(fù)制代碼 代碼如下:

<?php
require('chinese.php');
class PDF extends PDF_Chinese
{
function Header() //設(shè)置頁(yè)眉
{
$this->SetFont('GB','',10);
$this->Write(10,'XX公司產(chǎn)品名錄');
$this->Ln(20); //換行
}
function Footer() //設(shè)置頁(yè)腳
{
$this->SetY(-15);
$this->SetFont('GB','',10);
$this->Cell(0,10,'第'.$this->PageNo().'頁(yè)');
}
}

$conn = mysql_connect("localhost", "root", ""); //連接數(shù)據(jù)庫(kù)

mysql_select_db("product", $conn); //執(zhí)行SQL
$query_rs_prod = "SELECT * FROM product ORDER BY prod_id";
$rs_prod = mysql_query($query_rs_prod, $conn) or die(mysql_error());
$row_rs_prod = mysql_fetch_assoc($rs_prod);
$totalRows_rs_prod = mysql_num_rows($rs_prod);

$pdf=new PDF(); //創(chuàng)建新的FPDF對(duì)象
$pdf->AddGBFont(); //設(shè)置中文字體
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)

$pdf->SetFont('GB','',10); //設(shè)置字體樣式

$header=array('產(chǎn)品編號(hào)','產(chǎn)品名稱','產(chǎn)品類型','產(chǎn)品單價(jià)'); //設(shè)置表頭
$width=array(20,80,40,20); //設(shè)置每列寬度

for($i=0;$i<count($header);$i++) //循環(huán)輸出表頭
$pdf->Cell($width[$i],6,$header[$i],1);
$pdf->Ln();

do //循環(huán)輸出表體
{
$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("product.pdf", true); //下載PDF文件
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件
$pdf=new FPDF('P', 'mm', 'A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)
$pdf->SetFont('Courier','I',20); //設(shè)置字體樣式
$pdf->Cell(0,0,'Hello World!'); //增加一個(gè)單元格
$pdf->Output(); //輸出PDF到瀏覽器
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件
$pdf=new FPDF('P', 'mm', 'A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)
$pdf->SetFont('Courier','I',20); //設(shè)置字體樣式
$pdf->Image('sight.jpg',20,20,0,0); //增加一張圖片,文件名為sight.jpg
$pdf->Output(); //輸出PDF到瀏覽器
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件
$pdf=new FPDF(‘P', ‘mm', ‘A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)
$pdf->SetFont('Courier','I',20); //設(shè)置字體樣式
$pdf->Cell(60,10,'Hello World!',1); //增加一個(gè)單元格 邊框?yàn)?
$pdf->Output(); //輸出PDF到瀏覽器
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件
$pdf=new FPDF('P', 'mm', 'A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)

$pdf->SetFont('Arial','',14); //設(shè)置字體樣式

$header=array('Name','Age','Sex','Salary'); //設(shè)置表頭
$data=array(); //設(shè)置表體
$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); //設(shè)置每列寬度

for($i=0;$i<count($header);$i++) //循環(huán)輸出表頭
$pdf->Cell($width[$i],6,$header[$i],1);
$pdf->Ln();

foreach($data as $row) //循環(huán)輸出表體
{
$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到瀏覽器
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件
$pdf=new FPDF('P', 'mm', 'A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)
$pdf->SetFont('Courier','I',20); //設(shè)置字體樣式
$pdf->Cell(0,0,'你好,F(xiàn)PDF'); //增加一個(gè)單元格并輸出中文
$pdf->Output(); //輸出PDF到瀏覽器
?>

復(fù)制代碼 代碼如下:

<?php
require('chinese.php');
class PDF extends PDF_Chinese
{
function Header() //設(shè)定頁(yè)眉
{
$this->SetFont('GB','',10);
$this->Write(10,'FPDF中文測(cè)試');
$this->Ln(20);
}

function Footer() //設(shè)定頁(yè)腳
{
$this->SetY(-15);
$this->SetFont('GB','',10);
$this->Cell(0,10,'第'.$this->PageNo().'頁(yè)');
}
}

$pdf=new PDF(); //創(chuàng)建PDF文檔
$pdf->AddGBFont();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('GB','I',20);
$pdf->Cell(0,10,'你好,F(xiàn)PDF'); //輸出一段中文
$pdf->Output();
?>

復(fù)制代碼 代碼如下:

<?php
$conn = mysql_connect("localhost", "root", ""); //連接數(shù)據(jù)庫(kù)
$colname_rs_article = $_GET['id']; //獲取參數(shù)id

mysql_select_db("cms", $conn); //執(zhí)行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());
$row_rs_article = mysql_fetch_assoc($rs_article);
$totalRows_rs_article = mysql_num_rows($rs_article);

function conv($Text) //對(duì)返回文本進(jìn)行處理
{
$Text=htmlspecialchars($Text); //轉(zhuǎn)換HTML關(guān)鍵字符
$Text=nl2br($Text); //轉(zhuǎn)換換行符
return $Text;
}
?>
<p align="center"><B><?php echo $row_rs_article['title']; ?></B></p>
<p align="center"><font size=2><?php echo $row_rs_article['author']; ?> | <a href="showpdf.php?id=<?php echo $row_rs_article['article_id']; ?>">下載PDF文檔</a></font></p>
<HR>
<p><?php echo conv($row_rs_article['content']); ?></p>

復(fù)制代碼 代碼如下:

<?php
require('chinese.php');
class PDF extends PDF_Chinese
{
function Header() //設(shè)置頁(yè)眉
{
$this->SetFont('GB','',10);
$this->Write(10,'文章系統(tǒng) - XX網(wǎng)站');
$this->Ln(20); //換行
}
function Footer() //設(shè)置頁(yè)腳
{
$this->SetY(-15);
$this->SetFont('GB','',10);
$this->Cell(0,10,'第'.$this->PageNo().'頁(yè)');
}
}
//主程序開(kāi)始
$conn = mysql_connect("localhost", "root", ""); //連接數(shù)據(jù)庫(kù)
$colname_rs_article = $_GET['id']; //獲取參數(shù)id

mysql_select_db("cms", $conn); //執(zhí)行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());
$row_rs_article = mysql_fetch_assoc($rs_article);
$totalRows_rs_article = mysql_num_rows($rs_article);
//開(kāi)始創(chuàng)建PDF文檔
$pdf=new PDF();
$pdf->AddGBFont();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('GB','B',20);
$pdf->Cell(0,10,$row_rs_article['title']); //輸出文章標(biāo)題
$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 != "") //循環(huán)逐頁(yè)將文章內(nèi)容寫(xiě)入PDF
{
$length = strlen($content); //獲取文章長(zhǎng)度
$output = substr($content, 0, 1024); //獲取本頁(yè)輸出內(nèi)容,每1024個(gè)字符為1頁(yè)
$pdf->Cell(0,10,$output); //輸出文章內(nèi)容
$content = substr($content, 1024, $length); //獲取剩余未輸出內(nèi)容
$pdf->AddPage(); //換頁(yè)
}
$pdf->Output($row_rs_article['title'].".pdf", true); //輸出PDF文件,文件名為文章標(biāo)題
?>

復(fù)制代碼 代碼如下:

<?php
define('FPDF_FONTPATH','font/'); //定義font文件夾所在路徑
require_once('fpdf/fpdf.php'); //包含fpdf類庫(kù)文件

class PDF extends FPDF
{
function Header() //設(shè)置頁(yè)眉
{
$this->SetFont('Arial','B',15); //設(shè)置頁(yè)眉字體
$this->Cell(80); //移動(dòng)單元格
$this->Cell(30,10,'Title'); //寫(xiě)入頁(yè)眉文字
$this->Ln(20); //換行
}

function Footer() //設(shè)置頁(yè)腳
{
$this->SetY(-15); //設(shè)置頁(yè)腳所在位置
$this->SetFont('Arial','I',8); //設(shè)置頁(yè)腳字體
$this->Cell(0,10,'Page - '.$this->PageNo()); //輸出當(dāng)前頁(yè)碼作為頁(yè)腳內(nèi)容
}
}

$pdf=new PDF('P', 'mm', 'A4'); //創(chuàng)建新的FPDF對(duì)象,豎向放紙,單位為毫米,紙張大小A4
$pdf->Open(); //開(kāi)始創(chuàng)建PDF
$pdf->AddPage(); //增加一頁(yè)
$pdf->SetFont('Courier','I',20); //設(shè)置字體樣式
$pdf->Cell(0,0,'Hello World!'); //增加一個(gè)單元格
$pdf->Output(); //輸出PDF到瀏覽器
?>

相關(guān)文章

  • php獲得文件大小和文件創(chuàng)建時(shí)間的方法

    php獲得文件大小和文件創(chuàng)建時(shí)間的方法

    這篇文章主要介紹了php獲得文件大小和文件創(chuàng)建時(shí)間的方法,涉及php中filesize及fileatime函數(shù)的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • php中++i 與 i++ 的區(qū)別

    php中++i 與 i++ 的區(qū)別

    php中++i 與 i++ 的區(qū)別介紹,需要的朋友可以參考下
    2012-08-08
  • PHP實(shí)現(xiàn)簡(jiǎn)單實(shí)用的驗(yàn)證碼類

    PHP實(shí)現(xiàn)簡(jiǎn)單實(shí)用的驗(yàn)證碼類

    這篇文章主要介紹了PHP實(shí)現(xiàn)簡(jiǎn)單實(shí)用的驗(yàn)證碼類,包含驗(yàn)證碼常用的隨機(jī)驗(yàn)證碼、干擾線、圖片生成與輸出等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • php算法實(shí)例分享

    php算法實(shí)例分享

    本文給大家分享了幾個(gè)常見(jiàn)的php算法的實(shí)例代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
    2015-07-07
  • PHP 裁剪圖片成固定大小代碼方法

    PHP 裁剪圖片成固定大小代碼方法

    任意圖像裁剪成固定大小,圖像不變形,空白處拉伸填充,圖像始終鋪滿,不留空白,用過(guò)bcastr的朋友應(yīng)該知道。
    2009-09-09
  • 解析WordPress中的post_class與get_post_class函數(shù)

    解析WordPress中的post_class與get_post_class函數(shù)

    這篇文章主要介紹了WordPress中的post_class與get_post_class函數(shù),包括post_class()的PHP源碼的相應(yīng)介紹,需要的朋友可以參考下
    2016-01-01
  • PHP實(shí)現(xiàn)加密的幾種方式介紹

    PHP實(shí)現(xiàn)加密的幾種方式介紹

    這篇文章主要介紹了PHP實(shí)現(xiàn)加密的幾種方式,非常全面實(shí)用,都是項(xiàng)目中經(jīng)常需要用到的,需要的朋友可以參考下
    2015-02-02
  • php下嘗試使用GraphicsMagick的縮略圖功能

    php下嘗試使用GraphicsMagick的縮略圖功能

    現(xiàn)在,對(duì)一個(gè)Web程序員來(lái)說(shuō),圖像處理已經(jīng)屬于必會(huì)知識(shí)之一了。且不說(shuō)Flickr,Yupoo等專業(yè)圖片分享網(wǎng)站,就算是一個(gè)和圖片分享不沾邊的網(wǎng)站,也會(huì)用到很多圖片處理的功能,比如說(shuō):用戶上傳頭像,然后自動(dòng)生成縮略圖。
    2011-01-01
  • 如何在smarty中增加類似foreach的功能自動(dòng)加載數(shù)據(jù)

    如何在smarty中增加類似foreach的功能自動(dòng)加載數(shù)據(jù)

    本篇文章是對(duì)在smarty中增加類似foreach的功能自動(dòng)加載數(shù)據(jù)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • 深入解析PHP中逗號(hào)與點(diǎn)號(hào)的區(qū)別

    深入解析PHP中逗號(hào)與點(diǎn)號(hào)的區(qū)別

    大部分同學(xué)都知道逗號(hào)要比點(diǎn)號(hào)快,但就是不知道為什么,更不知道逗號(hào)與點(diǎn)號(hào)這兩者之間到底有什么區(qū)別。下面小編就來(lái)詳細(xì)的為大家介紹一下,需要的朋友可以過(guò)來(lái)參考下
    2013-08-08

最新評(píng)論