John
John

Reputation: 7137

TCPDF footer how to add columns

I'm using TCPDF and got the following function that adds page number to the footer. However this only centers the page numbering, i want to be able to add a description on the left and a reference number on the right. So in other words 3 columns, left column being left aligned with description, middle column with page number and centered and right column with reference number and right aligned.

class MYPDF extends TCPDF {

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
    $this->SetFont('Calibri', '', 8);
        // Page number

    $pageNumbers = 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages();

        $this->Cell(0, 10, $pageNumbers, 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

}

Upvotes: 3

Views: 1600

Answers (1)

olger
olger

Reputation: 492

Easiest thing to do is create three separate cells, one for each item, as follows:

    $this->Cell(30, 10, 'Description', 1, false, 'C', 0, '', 0, false, 'T', 'M');
    $this->Cell(130, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 1, false, 'C', 0, '', 0, false, 'T', 'C');
    $this->Cell(30, 10, 'Reference number', 1, false, 'C', 0, '', 0, false, 'T', 'M');

This will create footer looking like this (I turned $border to '1' so the border shows how the cell structure works). Of course you can adjust the sizes of the different cells if you need more space for the content.

enter image description here

Upvotes: 6

Related Questions