范曾绘画书法作品欣赏:php中FPDF类库应用

来源:百度文库 编辑:九乡新闻网 时间:2024/05/05 15:32:00

 php中FPDF类库应用收藏

 

view plaincopy to clipboardprint
  1. require('chinese.php');   
  2. class PDF extends PDF_Chinese   
  3. {   
  4.     function Header()                                   //设置页眉  
  5.     {   
  6.         $this->SetFont('GB','',10);   
  7.         $this->Write(10,'XX公司产品名录');   
  8.         $this->Ln(20);                                   //换行  
  9.     }  
  10.     function Footer()                                   //设置页脚   
  11.     {  
  12.         $this->SetY(-15);  
  13.         $this->SetFont('GB','',10);   
  14.         $this->Cell(0,10,'第'.$this->PageNo().'页');   
  15.     }   
  16. }   
  17.   
  18. $conn = mysql_connect("localhost", "root", "");                 //连接数据库  
  19.   
  20. mysql_select_db("product", $conn);                          //执行SQL  
  21. $query_rs_prod = "SELECT * FROM product ORDER BY prod_id";  
  22. $rs_prod = mysql_query($query_rs_prod, $conn) or die(mysql_error());  
  23. $row_rs_prod = mysql_fetch_assoc($rs_prod);  
  24. $totalRows_rs_prod = mysql_num_rows($rs_prod);  
  25.   
  26. $pdf=new PDF();                                     //创建新的FPDF对象  
  27. $pdf->AddGBFont();                                   //设置中文字体  
  28. $pdf->Open();                                            //开始创建PDF  
  29. $pdf->AddPage();                                     //增加一页  
  30.   
  31. $pdf->SetFont('GB','',10);                                   //设置字体样式  
  32.   
  33. $header=array('产品编号','产品名称','产品类型','产品单价');     //设置表头  
  34. $width=array(20,80,40,20);                              //设置每列宽度  
  35.   
  36. for($i=0;$i
  37.     $pdf->Cell($width[$i],6,$header[$i],1);  
  38. $pdf->Ln();  
  39.   
  40. do                                                  //循环输出表体  
  41. {  
  42.     $pdf->Cell($width[0],6,$row_rs_prod['prod_id'],1);  
  43.     $pdf->Cell($width[1],6,$row_rs_prod['prod_name'],1);  
  44.     $pdf->Cell($width[2],6,$row_rs_prod['prod_type'],1);  
  45.     $pdf->Cell($width[3],6,$row_rs_prod['prod_price'],1);  
  46.     $pdf->Ln();  
  47. } while ($row_rs_prod = mysql_fetch_assoc($rs_prod));  
  48.   
  49. $pdf->Output("product.pdf", true);                           //下载PDF文件  
  50. ?>  
  view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                  //包含fpdf类库文件  
  3. $pdf=new FPDF('P', 'mm', 'A4');             //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  4. $pdf->Open();                                //开始创建PDF  
  5. $pdf->AddPage();                         //增加一页  
  6. $pdf->SetFont('Courier','I',20);                 //设置字体样式  
  7. $pdf->Cell(0,0,'Hello World!');                  //增加一个单元格  
  8. $pdf->Output();                              //输出PDF到浏览器  
  9. ?>  

 

 

view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                  //包含fpdf类库文件  
  3. $pdf=new FPDF('P', 'mm', 'A4');             //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  4. $pdf->Open();                                //开始创建PDF  
  5. $pdf->AddPage();                         //增加一页  
  6. $pdf->SetFont('Courier','I',20);                 //设置字体样式  
  7. $pdf->Image('sight.jpg',20,20,0,0);              //增加一张图片,文件名为sight.jpg  
  8. $pdf->Output();                              //输出PDF到浏览器  
  9. ?>  

 

 

view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                  //包含fpdf类库文件  
  3. $pdf=new FPDF(‘P’, ‘mm’, ‘A4’);             //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  4. $pdf->Open();                                //开始创建PDF  
  5. $pdf->AddPage();                         //增加一页  
  6. $pdf->SetFont('Courier','I',20);                 //设置字体样式  
  7. $pdf->Cell(60,10,'Hello World!',1);              //增加一个单元格 边框为1  
  8. $pdf->Output();                              //输出PDF到浏览器  
  9. ?>  

 

 

view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                  //包含fpdf类库文件  
  3. $pdf=new FPDF('P', 'mm', 'A4');             //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  4. $pdf->Open();                                //开始创建PDF  
  5. $pdf->AddPage();                         //增加一页  
  6.   
  7. $pdf->SetFont('Arial','',14);                    //设置字体样式  
  8.   
  9. $header=array('Name','Age','Sex','Salary');     //设置表头  
  10. $data=array();                              //设置表体  
  11. $data[0] = array('Simon','24','Male','5,000.00');  
  12. $data[1] = array('Elaine','25','Female','6,000.00');  
  13. $data[2] = array('Susan','25','Female','7,000.00');  
  14. $data[3] = array('David','26','Male','8,000.00');  
  15.   
  16. $width=array(40,40,40,40);                  //设置每列宽度  
  17.   
  18. for($i=0;$i
  19.     $pdf->Cell($width[$i],6,$header[$i],1);  
  20. $pdf->Ln();  
  21.   
  22. foreach($data as $row)                      //循环输出表体  
  23. {  
  24.     $pdf->Cell($width[0],6,$row[0],1);  
  25.     $pdf->Cell($width[1],6,$row[1],1);  
  26.     $pdf->Cell($width[2],6,$row[2],1);  
  27.     $pdf->Cell($width[3],6,$row[3],1);  
  28.     $pdf->Ln();  
  29. }  
  30.   
  31. $pdf->Output();                              //输出PDF到浏览器  
  32. ?>  

 

 

view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                  //包含fpdf类库文件  
  3. $pdf=new FPDF('P', 'mm', 'A4');             //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  4. $pdf->Open();                                //开始创建PDF  
  5. $pdf->AddPage();                         //增加一页  
  6. $pdf->SetFont('Courier','I',20);                 //设置字体样式  
  7. $pdf->Cell(0,0,'你好,FPDF');                   //增加一个单元格并输出中文  
  8. $pdf->Output();                              //输出PDF到浏览器  
  9. ?>  

 

 

view plaincopy to clipboardprint
  1. require('chinese.php');   
  2. class PDF extends PDF_Chinese   
  3. {   
  4. function Header()                       //设定页眉  
  5. {   
  6. $this->SetFont('GB','',10);   
  7. $this->Write(10,'FPDF中文测试');   
  8. $this->Ln(20);   
  9. }   
  10.   
  11. function Footer()                       //设定页脚  
  12. {  
  13. $this->SetY(-15);  
  14. $this->SetFont('GB','',10);   
  15. $this->Cell(0,10,'第'.$this->PageNo().'页');   
  16. }   
  17. }   
  18.   
  19. $pdf=new PDF();                         //创建PDF文档  
  20. $pdf->AddGBFont();   
  21. $pdf->Open();   
  22. $pdf->AliasNbPages();   
  23. $pdf->AddPage();   
  24. $pdf->SetFont('GB','I',20);   
  25. $pdf->Cell(0,10,'你好,FPDF');          //输出一段中文  
  26. $pdf->Output();   
  27. ?>  

 

 

view plaincopy to clipboardprint
  1. $conn = mysql_connect("localhost", "root", "");                 //连接数据库  
  2. $colname_rs_article = $_GET['id'];                          //获取参数id  
  3.   
  4. mysql_select_db("cms", $conn);                          //执行SQL  
  5. $query_rs_article = sprintf("SELECT * FROM articles WHERE article_id = %s", $colname_rs_article);  
  6. $rs_article = mysql_query($query_rs_article, $conn) or die(mysql_error());  
  7. $row_rs_article = mysql_fetch_assoc($rs_article);  
  8. $totalRows_rs_article = mysql_num_rows($rs_article);  
  9.   
  10. function conv($Text)                                    //对返回文本进行处理  
  11. {  
  12. $Text=htmlspecialchars($Text);                              //转换HTML关键字符  
  13. $Text=nl2br($Text);                                         //转换换行符  
  14. return $Text;  
  15. }  
  16. ?>  
  17.   
  18.  | ">下载PDF文档

      

  19.   
  20.   

 

 

view plaincopy to clipboardprint
  1. require('chinese.php');   
  2. class PDF extends PDF_Chinese   
  3. {   
  4.     function Header()                                   //设置页眉  
  5.     {   
  6.         $this->SetFont('GB','',10);   
  7.         $this->Write(10,'文章系统 - XX网站');   
  8.         $this->Ln(20);                                   //换行  
  9.     }  
  10.     function Footer()                                   //设置页脚   
  11.     {  
  12.         $this->SetY(-15);  
  13.         $this->SetFont('GB','',10);   
  14.         $this->Cell(0,10,'第'.$this->PageNo().'页');   
  15.     }   
  16. }   
  17. //主程序开始  
  18. $conn = mysql_connect("localhost", "root", "");                 //连接数据库  
  19. $colname_rs_article = $_GET['id'];                          //获取参数id  
  20.   
  21. mysql_select_db("cms", $conn);                          //执行SQL  
  22. $query_rs_article = sprintf("SELECT * FROM articles WHERE article_id = %s", $colname_rs_article);  
  23. $rs_article = mysql_query($query_rs_article, $conn) or die(mysql_error());  
  24. $row_rs_article = mysql_fetch_assoc($rs_article);  
  25. $totalRows_rs_article = mysql_num_rows($rs_article);  
  26. //开始创建PDF文档  
  27. $pdf=new PDF();   
  28. $pdf->AddGBFont();   
  29. $pdf->Open();   
  30. $pdf->AliasNbPages();   
  31. $pdf->AddPage();   
  32. $pdf->SetFont('GB','B',20);   
  33. $pdf->Cell(0,10,$row_rs_article['title']);                       //输出文章标题  
  34. $pdf->Ln();                                          //换行  
  35. $pdf->SetFont('GB','',10);   
  36. $pdf->Cell(0,10,$row_rs_article['author']);                  //输出文章作者  
  37. $pdf->Ln();  
  38. $pdf->SetFont('GB','',12);  
  39. $content = $row_rs_article['content'];  
  40. while($content != "")                                       //循环逐页将文章内容写入PDF  
  41. {  
  42.     $length = strlen($content);                             //获取文章长度  
  43.     $output = substr($content, 0, 1024);                        //获取本页输出内容,每1024个字符为1页  
  44.     $pdf->Cell(0,10,$output);                            //输出文章内容  
  45.     $content = substr($content, 1024, $length);             //获取剩余未输出内容  
  46.     $pdf->AddPage();                                 //换页  
  47. }  
  48. $pdf->Output($row_rs_article['title'].".pdf", true);                 //输出PDF文件,文件名为文章标题  
  49. ?>  

 

 

view plaincopy to clipboardprint
  1. define('FPDF_FONTPATH','font/');                    //定义font文件夹所在路径  
  2. require_once('fpdf/fpdf.php');                      //包含fpdf类库文件  
  3.   
  4. class PDF extends FPDF  
  5. {  
  6.     function Header()                           //设置页眉  
  7.     {  
  8.         $this->SetFont('Arial','B',15);              //设置页眉字体  
  9.         $this->Cell(80);                         //移动单元格  
  10.         $this->Cell(30,10,'Title');                  //写入页眉文字  
  11.         $this->Ln(20);                           //换行  
  12.     }  
  13.       
  14.     function Footer()                           //设置页脚  
  15.     {  
  16.         $this->SetY(-15);                        //设置页脚所在位置  
  17.         $this->SetFont('Arial','I',8);                   //设置页脚字体  
  18.         $this->Cell(0,10,'Page - '.$this->PageNo());  //输出当前页码作为页脚内容  
  19.     }  
  20. }  
  21.   
  22. $pdf=new PDF('P', 'mm', 'A4');              //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4  
  23. $pdf->Open();                            //开始创建PDF  
  24. $pdf->AddPage();                     //增加一页  
  25. $pdf->SetFont('Courier','I',20);             //设置字体样式  
  26. $pdf->Cell(0,0,'Hello World!');              //增加一个单元格  
  27. $pdf->Output();                          //输出PDF到浏览器  
  28. ?>