源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php FPDF类库应用实现代码

  • 时间:2021-12-19 02:58 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php FPDF类库应用实现代码
[url=showpdf.php?id=<?php echo $row_rs_article[]<HR> <p><?php echo conv($row_rs_article['content']); ?></p>
<?php require('chinese.php'); class PDF extends PDF_Chinese { function 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 = $_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()); $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->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文件,文件名为文章标题 ?>
[u]复制代码[/u] 代码如下:
<?php define('FPDF_FONTPATH','font/'); //定义font文件夹所在路径 require_once('fpdf/fpdf.php'); //包含fpdf类库文件 class PDF extends FPDF { 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到浏览器 ?>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部