AliasNbPages()
- function AliasNbPages($alias='{nb}')
- {
- // 设置页面总数的别名
- $this->AliasNbPages = $alias;
- }
该方法用于设置页面总数的别名,默认该别名是 {nb},例如你在文档的每个页眉或页脚输出了“共 {nb} 页”,在文档输出的时候该内容会自动替换成页面总数。
Open()
- function Open()
- {
- // 文档开始
- $this->state = 1;
- }
前面一直在设置PDF文档的一些东西,这里则正式开始一个文档了,把文档状态标记为1。
Close()
- function Close()
- {
- // 结束文档
- if($this->state == 3)
- return;
- if($this->page == 0)
- $this->AddPage();
- // 处理页脚,调用方法 Footer()
- $this->InFooter = true;
- $this->Footer();
- $this->InFooter = false;
- // 关闭页面,调用方法 _endpage()
- $this->_endpage();
- // 关闭文档,调用方法 _enddoc()
- $this->_enddoc();
- }
关闭文档时将文档状态设置为3,然后检查文档页面数,如果为0,即没有任何页面,则添加一个空白页( AddPage() ),处理页脚,关闭页面和文档。
AddPage()
- function AddPage($orientation='', $format='')
- {
- // 开始新的一页
- if($this->state == 0)
- $this->Open();
- $family = $this->FontFamily;
- $style = $this->FontStyle.($this->underline ? 'U' : '');
- $size = $this->FontSizePt;
- $lw = $this->LineWidth;
- $dc = $this->DrawColor;
- $fc = $this->FillColor;
- $tc = $this->TextColor;
- $cf = $this->ColorFlag;
- if($this->page > 0)
- {
- // 处理页脚
- $this->InFooter = true;
- $this->Footer();
- $this->InFooter = false;
- // 关闭前一页
- $this->_endpage();
- }
- // 开始新一页
- $this->_beginpage($orientation,$format);
- // 以长方形设置线条大写样式
- $this->_out('2 J');
- // 设置线的粗细
- $this->LineWidth = $lw;
- $this->_out(sprintf('%.2F w', $lw*$this->k));
- // 设置字体
- if($family)
- $this->SetFont($family,$style,$size);
- // 设置颜色
- $this->DrawColor = $dc;
- if($dc != '0 G')
- $this->_out($dc);
- $this->FillColor = $fc;
- if($fc != '0 g')
- $this->_out($fc);
- $this->TextColor = $tc;
- $this->ColorFlag = $cf;
- // 处理页眉
- $this->InHeader = true;
- $this->Header();
- $this->InHeader = false;
- // 恢复线条粗细
- if($this->LineWidth != $lw)
- {
- $this->LineWidth = $lw;
- $this->_out(sprintf('%.2F w',$lw*$this->k));
- }
- // 恢复字体
- if($family)
- $this->SetFont($family,$style,$size);
- // 恢复颜色
- if($this->DrawColor != $dc)
- {
- $this->DrawColor = $dc;
- $this->_out($dc);
- }
- if($this->FillColor != $fc)
- {
- $this->FillColor = $fc;
- $this->_out($fc);
- }
- $this->TextColor = $tc;
- $this->ColorFlag = $cf;
- }
#1
