Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text color in header in TCPDF

Anyone knows how to change a color of text in header and footer and also line color?? Simply setting these two colors before setting header/footer doesn't work with:

$pdf->SetTextColor(180);
$pdf->SetDrawColor(70);

Thanks.

like image 759
jazkat Avatar asked Dec 22 '22 02:12

jazkat


2 Answers

Ok, found it, I guess you have to change font in Header() and Footer() public functions (in tcpdf.php) For text color find:

$this->SetTextColor(0, 0, 0); 

in Header() and/or Footer() functions and change it to your liking.

As for line color, find:

$this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(70, 70, 70)));

and change the 'color' array at the end.

cheers..

like image 197
jazkat Avatar answered Jan 13 '23 11:01

jazkat


or alternatively you can do it this way too :

By extending core class and extending just its footer function :

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
    //set text color
$this->SetTextColor(255,0,0);

}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

Hope this will help someone.

like image 45
atif Avatar answered Jan 13 '23 11:01

atif