Search code examples
phptcpdf

How can I use a multiline footer in TCPDF?


// Page footer
public function Footer() {
    // Position at 15 mm from bottom
    $this->SetY(-15);
    // Set font
    $this->SetFont('helvetica', 'I', 8);
    // Page number
    $this->Cell(0, 10, 'Seite '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}

Right now my footer looks like this:

enter image description here]

But I need a more komplex footer with multiple lines:

enter image description here]

How can I achieve this?

I tried to solve it with this stack overflow suggestion:

TCPDF Multiple Footers

But I had no success.


Solution

  • Try using MultiCell with some cell width combination, like this:

    public function Footer() {
        // Make more space in footer for additional text
        $this->SetY(-25);
    
        $this->SetFont('helvetica', 'I', 8);
    
        // Page number
        $this->Cell(0, 10, 'Seite '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    
        // New line in footer
        $this->Ln(8);
    
        // First line of 3x "sometext"
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
    
        // New line for next 3 elements
        $this->Ln(4);
    
        // Second line of 3x "sometext"
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
        $this->MultiCell(55, 10, 'Sometext', 0, 'C', 0, 0, '', '', true, 0, false, true, 10, 'M');
    
        // and so on...
    }
    

    You can see more examples of how to use MultiCell function in TCPDF official examples: https://tcpdf.org/examples/example_005/