php中FPDF类库应用
《php中FPDF类库应用》由会员分享,可在线阅读,更多相关《php中FPDF类库应用(35页珍藏版)》请在装配图网上搜索。
1、php 中 FPDF 类库应用php 中 FPDF 类库应用收藏 view plaincopy to clipboardprint<?phprequire(chinese.php);class PDF extends PDF_Chinesefunction Header()/设置页眉$this->SetFont(GB,10);$this->Write(10,XX 公司产品名录);$this->Ln(20);/换行function Footer()/设置页脚$this->SetY(-15);$this->SetFont(GB,10);$this-&g
2、t;Cell(0,10,第.$this->PageNo().页);$conn=mysql_connect(localhost,root,);/连接数据库mysql_select_db(product,$conn);/执行 SQL$query_rs_prod=SELECT*FROM product ORDER BYprod_id;$rs_prod=mysql_query($query_rs_prod,$conn)ordie(mysql_error();$row_rs_prod=mysql_fetch_assoc($rs_prod);$totalRows_rs_prod=mysql_num_
3、rows($rs_prod);$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<count($header);$i+)/循环输出表头$pdf->Cell($width$i,6,$header$i,
4、1);$pdf->Ln();do/循环输出表体$pdf->Cell($width0,6,$row_rs_prodprod_id,1);$pdf->Cell($width1,6,$row_rs_prodprod_name,1);$pdf->Cell($width2,6,$row_rs_prodprod_type,1);$pdf->Cell($width3,6,$row_rs_prodprod_price,1);$pdf->Ln();while($row_rs_prod=mysql_fetch_assoc($rs_prod);$pdf->Output(pr
5、oduct.pdf,true);/下载 PDF 文件?><?phprequire(chinese.php);class PDF extends PDF_Chinesefunction Header()/设置页眉$this->SetFont(GB,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
6、_connect(localhost,root,);连接数据库mysql_select_db(product,$conn);行 SQL$query_rs_prod=SELECT*FROM product ORDER BYprod_id;$rs_prod=mysql_query($query_rs_prod,$conn)ordie(mysql_error();$row_rs_prod=mysql_fetch_assoc($rs_prod);$totalRows_rs_prod=mysql_num_rows($rs_prod);$pdf=new PDF();/创建新的/执/设置页脚/换行FPDF
7、对象$pdf->AddGBFont();字体$pdf->Open();PDF$pdf->AddPage();/增加一页/设置字/开始创建/设置中文$pdf->SetFont(GB,10);体样式$header=array(产品编号,产品名称,产品类型,产品单价);/设置表头/设置每列$width=array(20,80,40,20);宽度for($i=0;$i<count($header);$i+)环输出表头/循$pdf->Cell($width$i,6,$header$i,1);$pdf->Ln();do$pdf->Cell($width0,6
8、,$row_rs_prodprod_id,1);$pdf->Cell($width1,6,$row_rs_prodprod_name,1);$pdf->Cell($width2,6,$row_rs_prodprod_type,1);$pdf->Cell($width3,6,$row_rs_prodprod_price,1);/循环输出表体$pdf->Ln();while($row_rs_prod=mysql_fetch_assoc($rs_prod);$pdf->Output(product.pdf,true);载 PDF 文件?>view plaincop
9、y to clipboardprint<?phpdefine(FPDF_FONTPATH,font/);font 文件夹所在路径require_once(fpdf/fpdf.php);类库文件$pdf=new FPDF(P,mm,A4);FPDF 对象,竖向放纸,单位为毫米,纸张大小$pdf->Open();创建 PDF$pdf->AddPage();$pdf->SetFont(Courier,I,20);/下/定义/包含 fpdf/创建新的A4/开始/增加一页/设置字体样式$pdf->Cell(0,0,Hello World!);/增加一个单元格$pdf->
10、;Output();/输出PDF 到浏览器?><?phpdefine(FPDF_FONTPATH,font/);所在路径require_once(fpdf/fpdf.php);件$pdf=new FPDF(P,mm,A4);/创建新的 FPDF 对/包含fpdf 类库文/定义 font 文件夹象,竖向放纸,单位为毫米,纸张大小 A4$pdf->Open();/开始创建 PDF/增加一页/设置字体样$pdf->AddPage();$pdf->SetFont(Courier,I,20);式$pdf->Cell(0,0,Hello World!);元格$pdf-&
11、gt;Output();/增加一个单/输出 PDF 到浏览器?> view plaincopy to clipboardprint<?phpdefine(FPDF_FONTPATH,font/);font 文件夹所在路径require_once(fpdf/fpdf.php);类库文件$pdf=new FPDF(P,mm,A4);FPDF 对象,竖向放纸,单位为毫米,纸张大小$pdf->Open();创建 PDF$pdf->AddPage();$pdf->SetFont(Courier,I,20);体样式$pdf->Image(sight
12、.jpg,20,20,0,0);/定义/包含 fpdf/创建新的A4/开始/增加一页/设置字/增加一张图片,文件名为 sight.jpg$pdf->Output();/输出PDF 到浏览器?><?phpdefine(FPDF_FONTPATH,font/);所在路径require_once(fpdf/fpdf.php);件$pdf=new FPDF(P,mm,A4);/创建新的 FPDF 对/包含fpdf 类库文/定义 font 文件夹象,竖向放纸,单位为毫米,纸张大小 A4$pdf->Open();/开始创建 PDF/增加一页/设置字体样$pdf->AddPag
13、e();$pdf->SetFont(Courier,I,20);式$pdf->Image(sight.jpg,20,20,0,0);片,文件名为 sight.jpg$pdf->Output();?>/增加一张图/输出 PDF 到浏览器 view plaincopy to clipboardprint<?phpdefine(FPDF_FONTPATH,font/);/定义font 文件夹所在路径require_once(fpdf/fpdf.php);/包含 fpdf类库文件$pdf=new FPDF(‘P’,‘
14、;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 到浏览器?><?phpdefine(FPDF_FONTPATH,font/);所在路径require_once(fpdf/fpdf.php);
15、件$pdf=new FPDF(‘P’,‘mm’,‘A4’);/创建新的 FPDF 对象,竖向/包含fpdf 类库文/定义 font 文件夹放纸,单位为毫米,纸张大小 A4$pdf->Open();/开始创建 PDF/增加一页/设置字体样$pdf->AddPage();$pdf->SetFont(Courier,I,20);式$pdf->Cell(60,10,Hello World!,1);元格 边框为 1$pdf->Output();?>/增加一个单/输出 PDF 到浏览器 &
16、#160;view plaincopy to clipboardprint<?phpdefine(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);
17、/设置表头$data=array();/设置表体$data0=array(Simon,24,Male,5,000.00);$data1=array(Elaine,25,Female,6,000.00);$data2=array(Susan,25,Female,7,000.00);$data3=array(David,26,Male,8,000.00);$width=array(40,40,40,40);度for($i=0;$i<count($header);$i+)表头$pdf->Cell($width$i,6,$header$i,1);$pdf->Ln();foreach(
18、$data as$row)体$pdf->Cell($width0,6,$row0,1);$pdf->Cell($width1,6,$row1,1);$pdf->Cell($width2,6,$row2,1);$pdf->Cell($width3,6,$row3,1);$pdf->Ln();/设置每列宽/循环输出/循环输出表$pdf->Output();/输出PDF 到浏览器?><?phpdefine(FPDF_FONTPATH,font/);所在路径require_once(fpdf/fpdf.php);件$pdf=new FPDF(P,mm,A
19、4);/创建新的 FPDF 对/包含fpdf 类库文/定义 font 文件夹象,竖向放纸,单位为毫米,纸张大小 A4$pdf->Open();/开始创建 PDF/增加一页/设置字体样式/设置表头$pdf->AddPage();$pdf->SetFont(Arial,14);$header=array(Name,Age,Sex,Salary);$data=array();/设置表体$data0=array(Simon,24,Male,5,000.00);$data1=array(Elaine,25,Female,6,000.00);$data2=array(Susan,25,F
20、emale,7,000.00);$data3=array(David,26,Male,8,000.00);$width=array(40,40,40,40);/设置每列宽度/循环输出表for($i=0;$i<count($header);$i+)头$pdf->Cell($width$i,6,$header$i,1);$pdf->Ln();foreach($data as$row)$pdf->Cell($width0,6,$row0,1);$pdf->Cell($width1,6,$row1,1);$pdf->Cell($width2,6,$row2,1);$
21、pdf->Cell($width3,6,$row3,1);$pdf->Ln();$pdf->Output();?> view plaincopy to clipboardprint/输出 PDF 到浏览器/循环输出表体<?phpdefine(FPDF_FONTPATH,font/);/定义font 文件夹所在路径require_once(fpdf/fpdf.php);类库文件$pdf=new FPDF(P,mm,A4);FPDF 对象,竖向放纸,单位为毫米,纸张大小$pdf->Open();创建 PDF$pdf->AddPage(
22、);$pdf->SetFont(Courier,I,20);体样式$pdf->Cell(0,0,你好,FPDF);一个单元格并输出中文$pdf->Output();PDF 到浏览器?><?php/包含 fpdf/创建新的A4/开始/增加一页/设置字/增加/输出define(FPDF_FONTPATH,font/);所在路径require_once(fpdf/fpdf.php);件$pdf=new FPDF(P,mm,A4);/定义 font 文件夹/包含fpdf 类库文/创建新的 FPDF 对象,竖向放纸,单位为毫米,纸张大小 A4$pdf->Open();
23、/开始创建 PDF/增加一页/设置字体样$pdf->AddPage();$pdf->SetFont(Courier,I,20);式$pdf->Cell(0,0,你好,FPDF);元格并输出中文$pdf->Output();?> view plaincopy to clipboardprint/增加一个单/输出 PDF 到浏览器<?phprequire(chinese.php);class PDF extends PDF_Chinesefunction Header()/设定页眉$this->SetFont(GB,10);$this
24、->Write(10,FPDF 中文测试);$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,
25、10,你好,FPDF);/输出一段中文$pdf->Output();?><?phprequire(chinese.php);class PDF extends PDF_Chinesefunction Header()$this->SetFont(GB,10);$this->Write(10,FPDF 中文测试);$this->Ln(20);function Footer()$this->SetY(-15);/设定页脚/设定页眉$this->SetFont(GB,10);$this->Cell(0,10,第.$this->PageNo(
26、).页);$pdf=new PDF();/创建 PDF 文档$pdf->AddGBFont();$pdf->Open();$pdf->AliasNbPages();$pdf->AddPage();$pdf->SetFont(GB,I,20);$pdf->Cell(0,10,你好,FPDF);$pdf->Output();?> view plaincopy to clipboardprint<?php/输出一段中文$conn=mysql_connect(localhost,root,);/连接数据库$colname_rs
27、_article=$_GETid;/获取参数 idmysql_select_db(cms,$conn);/执行 SQL$query_rs_article=sprintf(SELECT*FROM articles WHEREarticle_id=%s,$colname_rs_article);$rs_article=mysql_query($query_rs_article,$conn)ordie(mysql_error();$row_rs_article=mysql_fetch_assoc($rs_article);$totalRows_rs_article=mysql_num_rows($r
28、s_article);function conv($Text)/对返回文本进行处理$Text=htmlspecialchars($Text);/转换 HTML 关键字符$Text=nl2br($Text);/转换换行符return$Text;?><p align=center><B><?php echo$row_rs_articletitle;?></B></p><p align=center><font size=2><?php echo$row_rs_articleauthor;?>|&l
29、t;ahref=showpdf.php?id=<?php echo$row_rs_articlearticle_id;?>>下载 PDF 文档</a></font></p><HR><p><?php echoconv($row_rs_articlecontent);?></p><?php$conn=mysql_connect(localhost,root,);据库$colname_rs_article=$_GETid;数 idmysql_select_db(cms,$conn);/执行 S
30、QL/获取参/连接数$query_rs_article=sprintf(SELECT*FROM articles WHEREarticle_id=%s,$colname_rs_article);$rs_article=mysql_query($query_rs_article,$conn)ordie(mysql_error();$row_rs_article=mysql_fetch_assoc($rs_article);$totalRows_rs_article=mysql_num_rows($rs_article);function conv($Text)进行处理$Text=htmlspec
31、ialchars($Text);HTML 关键字符$Text=nl2br($Text);符return$Text;?><p align=center><B><?php echo$row_rs_articletitle;?></B></p><p align=center><font size=2><?php echo$row_rs_articleauthor;?>|<ahref=showpdf.php?id=<?php/转换换行/转换/对返回文本echo$row_rs_article
32、article_id;?>>下载 PDF 文档</a></font></p><HR><p><?php echoconv($row_rs_articlecontent);?></p> view plaincopy to clipboardprint<?phprequire(chinese.php);class PDF extends PDF_Chinesefunction Header()/设置页眉$this->SetFont(GB,10);$this->Wri
33、te(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=$_GETid;/获取参数 idmysql_select_db(cms,$conn);/执行 SQL$query_rs_article=sprintf(SELECT
34、*FROM articles WHEREarticle_id=%s,$colname_rs_article);$rs_article=mysql_query($query_rs_article,$conn)ordie(mysql_error();$row_rs_article=mysql_fetch_assoc($rs_article);$totalRows_rs_article=mysql_num_rows($rs_article);/开始创建 PDF 文档$pdf=new PDF();$pdf->AddGBFont();$pdf->Open();$pdf->AliasNb
35、Pages();$pdf->AddPage();$pdf->SetFont(GB,B,20);$pdf->Cell(0,10,$row_rs_articletitle);/输出文章标题$pdf->Ln();/换行$pdf->SetFont(GB,10);$pdf->Cell(0,10,$row_rs_articleauthor);/输出文章作者$pdf->Ln();$pdf->SetFont(GB,12);$content=$row_rs_articlecontent;while($content!=)/循环逐页将文章内容写入 PDF$lengt
36、h=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_articletitle.pdf,true);/输出 PDF 文件,文件名为文章标题?><?phprequire(chinese.php);class PDF e
37、xtends PDF_Chinesefunction Header()/设置页眉$this->SetFont(GB,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=$_GETid;数 idm
38、ysql_select_db(cms,$conn);/执行 SQL/获取参/设置页脚/换行$query_rs_article=sprintf(SELECT*FROM articles WHEREarticle_id=%s,$colname_rs_article);$rs_article=mysql_query($query_rs_article,$conn)ordie(mysql_error();$row_rs_article=mysql_fetch_assoc($rs_article);$totalRows_rs_article=mysql_num_rows($rs_article);/开始
39、创建 PDF 文档$pdf=new PDF();$pdf->AddGBFont();$pdf->Open();$pdf->AliasNbPages();$pdf->AddPage();$pdf->SetFont(GB,B,20);$pdf->Cell(0,10,$row_rs_articletitle);/输出文章标题$pdf->Ln();$pdf->SetFont(GB,10);$pdf->Cell(0,10,$row_rs_articleauthor);输出文章作者$pdf->Ln();$pdf->SetFont(GB,12
40、);$content=$row_rs_articlecontent;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_articletitle.pdf,true);/输出 P
41、DF 文件,文件名为文章标题/换页/获取剩/输出文章/获取本页?> view plaincopy to clipboardprint<?phpdefine(FPDF_FONTPATH,font/);/定义 font 文件夹所在路径require_once(fpdf/fpdf.php);/包含fpdf 类库文件class PDF extends FPDFfunction Header()页眉$this->SetFont(Arial,B,15);置页眉字体$this->Cell(80);动单元格$this->Cell(30,10,Title);写
42、入页眉文字$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(Courie
43、r,I,20);/设置字体样式$pdf->Cell(0,0,Hello World!);/增加一个单元格$pdf->Output();/输出 PDF到浏览器?><?phpdefine(FPDF_FONTPATH,font/);件夹所在路径require_once(fpdf/fpdf.php);库文件class PDF extends FPDFfunction Header()$this->SetFont(Arial,B,15);$this->Cell(80);/设置页眉字体/设置页眉/包含 fpdf 类/定义 font 文/移动单元格/写入页眉文字$this
44、->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->AddPage();$pdf->SetFont(Courier,I,20);$pdf->Cell(0,0,Hello World!);$pdf->Output();?> /开始创建 PDF/增加一页/设置字体样式/增加一个单元格/输出 PDF 到浏览器
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。