tags:

views:

365

answers:

4

How do I edit a footer using tcpdf? I want to add current date & time at the footer. Please help.

A: 

After the EOD use the below code to overwrite the footer method.

 EOD;

 $txt = date("m/d/Y h:m:s");    

 // print a block of text using Write()
 $pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
ChuckO
A: 

Hi Chuck, Your solution adds the date to the end of the document, but not at the footer. Here's my code:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, "by ".$user_name." for " .$title);

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->AddPage();

$pdf->writeHTML($output, true, 0, false, false, '');

ob_end_clean();

$pdf->Output($fileName, "F");

I'm new to tcpdf, thus the code above was copied from tcpdf example files that came with the download. The current footer has "page 1/3" at the bottom left, but I would also like to add timestamp too along with the "page 1/3".

How can I do this? Thank you for replying.

lv949
A: 

I figured it out and here's the solution for others that might come across this thread.

Edit "tcpdf.php" file.

Search for "public function Footer()"

Add timestamp here:

$timestamp = date("m/d/Y h:m:s");

if (empty($this->pagegroups)) {

$pagenumtxt = ' Created on ' .$timestamp.' '.$this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();

} else {

$pagenumtxt = ' Created on ' .$timestamp.' '. $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();

}

lv949
A: 

You have to extend the TCPDF class and override the Footer() method as explained on the default example n. 3. Check the official http://www.tcpdf.org website and forums for further information.