您好,欢迎访问一九零五行业门户网

php中FPDF类库应用

?phprequire('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','',1
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, ); //连接数据库mysql_select_db(product, $conn); //执行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(); //创建新的fpdf对象$pdf->addgbfont(); //设置中文字体$pdf->open(); //开始创建pdf$pdf->addpage(); //增加一页$pdf->setfont('gb','',10); //设置字体样式$header=array('产品编号','产品名称','产品类型','产品单价'); //设置表头$width=array(20,80,40,20); //设置每列宽度for($i=0;$icell($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(product.pdf, true); //下载pdf文件?>  open(); //开始创建pdf$pdf->addpage(); //增加一页$pdf->setfont('courier','i',20); //设置字体样式$pdf->cell(0,0,'hello world!'); //增加一个单元格$pdf->output(); //输出pdf到浏览器?>
open(); //开始创建pdf$pdf->addpage(); //增加一页$pdf->setfont('courier','i',20); //设置字体样式$pdf->image('sight.jpg',20,20,0,0); //增加一张图片,文件名为sight.jpg$pdf->output(); //输出pdf到浏览器?>
open(); //开始创建pdf$pdf->addpage(); //增加一页$pdf->setfont('courier','i',20); //设置字体样式$pdf->cell(60,10,'hello world!',1); //增加一个单元格 边框为1$pdf->output(); //输出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;$icell($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到浏览器?>
open(); //开始创建pdf$pdf->addpage(); //增加一页$pdf->setfont('courier','i',20); //设置字体样式$pdf->cell(0,0,'你好,fpdf'); //增加一个单元格并输出中文$pdf->output(); //输出pdf到浏览器?>
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().'页'); } } $pdf=new pdf(); //创建pdf文档$pdf->addgbfont(); $pdf->open(); $pdf->aliasnbpages(); $pdf->addpage(); $pdf->setfont('gb','i',20); $pdf->cell(0,10,'你好,fpdf'); //输出一段中文$pdf->output(); ?>
| 下载pdf文档
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']; //获取参数idmysql_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文件,文件名为文章标题?>
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到浏览器?>
其它类似信息

推荐信息