【问题标题】:tcpdf center text not fully in centertcpdf 居中文本未完全居中
【发布时间】:2014-02-28 18:49:31
【问题描述】:

我正在尝试使页脚文本居中

function Footer(){
    $txt = 'Page %s of %s';
    if (empty($this->pagegroups)) {
        $txt = sprintf($txt, $this->getAliasNumPage(), $this->getAliasNbPages());
    } else {
        $txt = sprintf($txt, $this->getPageNumGroupAlias(), $this->getPageGroupAlias());
    }
    $this->MultiCell(0, 0, $txt, 1, 'C', false, 1, PDF_MARGIN_LEFT, $this->y);
}

正如您在图像中看到的那样,单元格的位置正确,问题在于文本居中。

如果我将 MultiCell 更改为更直接的东西,我会得到相同的结果:

$this->SetXY(PDF_MARGIN_LEFT, $this->y);
$this->Cell(0, 0, $txt, 1, 1, 'C');

【问题讨论】:

标签: php tcpdf


【解决方案1】:

不知何故,getAliasNumPage()getPageNumGroupAlias() 在右侧添加了一堆空白。我不确定为什么。但我知道改用PageNo()getGroupPageNo() 可以解决这个问题。

这是对我有用的代码:

public function Footer() {

    $this->SetY(-15); //not present in your code but was necessary for me to have the footer be positioned correctly

    $txt = 'Page %s of %s';
        if (empty($this->pagegroups)) {
            $txt = sprintf($txt, $this->PageNo(), $this->getAliasNbPages());
        } else {
            $txt = sprintf($txt, $this->getGroupPageNo(), $this->getPageGroupAlias());
        }
        $this->MultiCell(0, 0, $txt, 1, 'C', false, 1);
        }
    }

【讨论】:

  • getAliasNumPage() 返回由“真实”页码替换的别名。这个别名是“{:ptp:}”,看起来中心的计算使用这个值而不是实际的页码。我想这是一个错误......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 2021-07-28
  • 2012-01-02
  • 2014-03-02
相关资源
最近更新 更多