2014-02-28 21 views
1

我試圖居中頁腳文本TCPDF中心的文字並不完全在中心

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); 
} 

,你可以在小區得到正確定位的圖片中看到,問題是居中的文本。

enter image description here

我得到同樣的結果,如果我改變該多的東西更直截了當:

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

重複: http://stackoverflow.com/questions/5485295/tcpdf-pagenumbers-not-exactly-right-aligned – user2345998

回答

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); 
     } 
    } 
+0

getAliasNumPage()返回alis被「真實」頁碼取代。這個別名是「{:ptp:}」,它看起來像是居中計算使用此值而不是實際頁碼。 我想這是一個錯誤... – user2345998