how to change the header and logo in TCPDF in codeigniter?

11,785

You have to extend the base tcpdf class into Your Own and override the logo logic.

Then call new YourTcpdf() instead.

require_once('tcpdf_include.php');


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES.'logo_example.jpg';
        $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

 
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
 // set document information
$pdf->SetCreator(PDF_CREATOR);    
$pdf->SetAuthor('Change me'); 
$pdf->SetTitle('Financial Report');       
$pdf->SetSubject('Yearly Customer Finanacial Report'); 
$pdf->SetKeywords('Purchase, Sale, Order, Payment');
  // set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->setFooterData(array(0,64,0), array(0,64,128));

A full example can be found here: https://tcpdf.org/examples/example_003/

Share:
11,785

Related videos on Youtube

Next Door
Author by

Next Door

Ctrl+Shift+Del

Updated on June 04, 2022

Comments

  • Next Door
    Next Door almost 2 years

    enter image description herethis is the header code, in view which is generating pdf, Even I tried to change the suspected code, still it is producing the same output..

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 
     'UTF-8', false);
    
    // set document information
      $pdf->SetCreator(PDF_CREATOR);
      $pdf->SetAuthor('Change me');
     $pdf->SetTitle('Financial Report');
     $pdf->SetSubject('Yearly Customer Finanacial Report');
     $pdf->SetKeywords('Purchase, Sale, Order, Payment');
    
      // set default header data
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 
      PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), 
      array(0,64,100));
      $pdf->setFooterData(array(0,64,0), array(0,64,128));
    
    • Next Door
      Next Door almost 7 years
      but, how dear? it is sth quite new for me...
    • Doug
      Doug almost 7 years
      Exactly how I've said in the post below.
    • Next Door
      Next Door almost 7 years
      okay, Let me test it with a fresh mind.... you will be rewarded stars, if I achieved what i want...