php fpdf 生成表格总结


一直都在了解FPDF 生成PDF,和一些基于FPDF的生成PDF的类,没有一个适合的报表方案.

  将网页生成PDF是一种好的方法```但得控制表格````种种原因,触使我自己写一个方法来生成PDF

  报表.

  须下载fpdf 和fpdf 中文化类.

  这过程中,得处理中文乱码,....

  效果如下:

  原码如下:

<?
require('chinese.php');
$pdf=new PDF_Chinese();
$pdf->AddGBFont('simsun','宋体');
$pdf->Open();
$pdf->AddPage();
  
$pdf->SetAutoPageBreak(true);
$pdf->SetFont('simsun','',10);
  
$conn=mysql_connect('localhost','root','');
  
mysql_select_db('j',$conn);
  
mysql_query("SET NAMES 'gb2312'");
  
$sql=mysql_query("select * from tssb limit 0,565");
  
$pdf->SetY(20);
  
while(($array =mysql_fetch_array($sql)) != false)
{
  
$pdf->SetX(15);
$Mywidth=array(15,20,20,40,20,20,20,20);
$Mytable=array($array["ls"],$array["cd"],$array["in"],$array["cm"],$array["h"],$array["c"],$array["n"],$array["d"]);
$pdf->Row($Mywidth,$Mytable,10);
$pdf->ln();
}
  
$pdf->Output();
?>
  
新增函数:
  
class PDF_Chinese extends FPDF
{
  
//表格输出
function Row($Arr,$Row,$MyHeight){
$MyTable=$Row;
//SetWidths($arr);
$Width=$Arr;
for($i=0;$i<count($Width);$i++){              //循环输出表头
// $this->SetX(20);
$this->Cell($Width[$i],$MyHeight,$MyTable[$i],1,0);
// $this->Ln();
}
}
  
这样一个表格就完整输出啦``
  
附中文类:
  
<?php
require('fpdf.php');
  
$Big5_widths=array(' '=>250,'!'=>250,'"'=>408,'#'=>668,'


« 
» 

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3