문제

I am trying to center the footer text

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

As you can see in the image the cell is getting positioned correctly, the problem is with centering the text.

enter image description here

I get the same result if I change the MultiCell to something more straight forward:

$this->SetXY(PDF_MARGIN_LEFT, $this->y);
$this->Cell(0, 0, $txt, 1, 1, 'C');
도움이 되었습니까?

해결책

Somehow getAliasNumPage() and getPageNumGroupAlias() add a bunch of whitespace to the right. I am unsure why. But I know that using PageNo() and getGroupPageNo() instead will fix it.

This is the code that worked for me:

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);
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top