也许过去我不是一个好孩子,但现在我要做个好爸爸...... 注册 | 登陆

FPDF代码研究(Part 5)

AliasNbPages()
  1. function AliasNbPages($alias='{nb}')
  2. {
  3.     // 设置页面总数的别名
  4.     $this->AliasNbPages = $alias;
  5. }

  该方法用于设置页面总数的别名,默认该别名是 {nb},例如你在文档的每个页眉或页脚输出了“共 {nb} 页”,在文档输出的时候该内容会自动替换成页面总数。

Open()
  1. function Open()
  2. {
  3.     // 文档开始
  4.     $this->state = 1;
  5. }

  前面一直在设置PDF文档的一些东西,这里则正式开始一个文档了,把文档状态标记为1。

Close()
  1. function Close()
  2. {
  3.     // 结束文档
  4.     if($this->state == 3)
  5.         return;
  6.     if($this->page == 0)
  7.         $this->AddPage();
  8.     // 处理页脚,调用方法 Footer()
  9.     $this->InFooter = true;
  10.     $this->Footer();
  11.     $this->InFooter = false;
  12.     // 关闭页面,调用方法 _endpage()
  13.     $this->_endpage();
  14.     // 关闭文档,调用方法 _enddoc()
  15.     $this->_enddoc();
  16. }

  关闭文档时将文档状态设置为3,然后检查文档页面数,如果为0,即没有任何页面,则添加一个空白页( AddPage() ),处理页脚,关闭页面和文档。

AddPage()
  1. function AddPage($orientation=''$format='')   
  2. {   
  3.     // 开始新的一页   
  4.     if($this->state == 0)   
  5.         $this->Open();   
  6.     $family = $this->FontFamily;   
  7.     $style = $this->FontStyle.($this->underline ? 'U' : '');   
  8.     $size = $this->FontSizePt;   
  9.     $lw = $this->LineWidth;   
  10.     $dc = $this->DrawColor;   
  11.     $fc = $this->FillColor;   
  12.     $tc = $this->TextColor;   
  13.     $cf = $this->ColorFlag;   
  14.     if($this->page > 0)   
  15.     {   
  16.         // 处理页脚   
  17.         $this->InFooter = true;   
  18.         $this->Footer();   
  19.         $this->InFooter = false;   
  20.         // 关闭前一页   
  21.         $this->_endpage();   
  22.     }   
  23.     // 开始新一页   
  24.     $this->_beginpage($orientation,$format);   
  25.     // 以长方形设置线条大写样式   
  26.     $this->_out('2 J');   
  27.     // 设置线的粗细   
  28.     $this->LineWidth = $lw;   
  29.     $this->_out(sprintf('%.2F w'$lw*$this->k));   
  30.     // 设置字体   
  31.     if($family)   
  32.         $this->SetFont($family,$style,$size);   
  33.     // 设置颜色   
  34.     $this->DrawColor = $dc;   
  35.     if($dc != '0 G')   
  36.         $this->_out($dc);   
  37.     $this->FillColor = $fc;   
  38.     if($fc != '0 g')   
  39.         $this->_out($fc);   
  40.     $this->TextColor = $tc;   
  41.     $this->ColorFlag = $cf;   
  42.     // 处理页眉   
  43.     $this->InHeader = true;   
  44.     $this->Header();   
  45.     $this->InHeader = false;   
  46.     // 恢复线条粗细   
  47.     if($this->LineWidth != $lw)   
  48.     {   
  49.         $this->LineWidth = $lw;   
  50.         $this->_out(sprintf('%.2F w',$lw*$this->k));   
  51.     }   
  52.     // 恢复字体   
  53.     if($family)   
  54.         $this->SetFont($family,$style,$size);   
  55.     // 恢复颜色   
  56.     if($this->DrawColor != $dc)   
  57.     {   
  58.         $this->DrawColor = $dc;   
  59.         $this->_out($dc);   
  60.     }   
  61.     if($this->FillColor != $fc)   
  62.     {   
  63.         $this->FillColor = $fc;   
  64.         $this->_out($fc);   
  65.     }   
  66.     $this->TextColor = $tc;   
  67.     $this->ColorFlag = $cf;   
  68. }  

  

Tags: php, fpdf

« 上一篇 | 下一篇 »

只显示5条记录相关文章

截取固定长度UTF-8字符串的PHP函数 (浏览: 34265, 评论: 2)
FPDF代码研究(Part 4) (浏览: 11606, 评论: 1)
FPDF代码研究(Part 3) (浏览: 11838, 评论: 0)
FPDF代码研究(Part 2,构造函数) (浏览: 22514, 评论: 0)
FPDF代码研究(Part 1,类的属性) (浏览: 11080, 评论: 0)

1条记录访客评论

看了半天,一点都没懂啊,

好迷茫了.

Post by 99吊车网 on 2009, February 20, 2:29 PM 引用此文发表评论 #1


发表评论

评论内容 (必填):