Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put HTML data into header of tcpdf?

I'm using the tcpdf library to generate the pdf document. I'm using smarty template engine to hold the data. Below is the script to put in the header data:

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'PQR', 
'XYZ');

I want to put HTML table content of smarty template in place of XYZ, the table content is going to be dynamic(meaning the data in table may vary for each PDF document).

like image 943
PHPLover Avatar asked Jan 24 '13 07:01

PHPLover


2 Answers

I used the following method to set header

$PDF_HEADER_LOGO = "logo.png";//any image file. check correct path.
$PDF_HEADER_LOGO_WIDTH = "20";
$PDF_HEADER_TITLE = "This is my Title";
$PDF_HEADER_STRING = "Tel 1234567896 Fax 987654321\n"
. "E [email protected]\n"
. "www.abc.com";
$pdf->SetHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $PDF_HEADER_TITLE, $PDF_HEADER_STRING);

This is work for me.

like image 143
vijay Avatar answered Oct 18 '22 00:10

vijay


You must instance your PDF class and extend the TCPDF class. After your PDF class should look like this:

class MyTCPDF extends TCPDF{
  public function Header(){
     $html = '<table>...</table>';
     $this->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'top', $autopadding = true);
  }
}

You must adapt this to your own project.

like image 25
vinzcoco Avatar answered Oct 18 '22 01:10

vinzcoco