Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF Align Left Center Right in single line

Tags:

php

tcpdf

I want to create a footer for a PDF document that contains the date left aligned, the creator centered and the page right aligned. These should be in a single line. I tried the following code:

$this->Cell(0, 10, $date->format('d.m.Y'), 0, false, 'L', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 10, 'Creator', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');

The creator is shifted to the right and overlays with the pages:

PDF Document Footer

Does anybody have a solution for that problem?

like image 395
Benny Avatar asked Mar 05 '13 01:03

Benny


1 Answers

You need to set the width of the Cell(), as according to the docs http://www.tcpdf.org/doc/code/classTCPDF.html#a33b265e5eb3e4d1d4fedfe29f8166f31 your $date->format('d.m.Y') Cell() is extending to the right margin, forcing the other cells on the line to the right margin.

$w (float) Cell width. If 0, the cell extends up to the right margin.

Try something like (may have to adjust based on font size)

$this->Cell(20, 10, $date->format('d.m.Y'), 0, false, 'L', 0, '', 0, false, 'T', 'M');   
$this->Cell(20, 10, 'Creator', 0, false, 'C', 0, '', 0, false, 'T', 'M'); 
$this->Cell(20, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
like image 167
Sean Avatar answered Sep 22 '22 12:09

Sean