Skip to content Skip to sidebar Skip to footer

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 da

Solution 1:

As @vinzcoco says, you must extend TCPDF to achieve what you want. Here is a simple improvement that I think it could be useful for you:

class MyTCPDF extends TCPDF {

    var $htmlHeader;

    public function setHtmlHeader($htmlHeader) {
        $this->htmlHeader = $htmlHeader;
    }

    public function Header() {
        $this->writeHTMLCell(
            $w = 0, $h = 0, $x = '', $y = '',
            $this->htmlHeader, $border = 0, $ln = 1, $fill = 0,
            $reseth = true, $align = 'top', $autopadding = true);
    }

}

Now, once you've got your MyTCPDF object available, you just need to do this to set the HTML header content:

$mytcpdfObject->setHtmlHeader('<table>...</table>');

and the HTML content won't be hardcoded into the Header() method (more flexible for you).


Solution 2:

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 abc@gmail.com\n"
. "www.abc.com";
$pdf->SetHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $PDF_HEADER_TITLE, $PDF_HEADER_STRING);

This is work for me.


Solution 3:

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.


Post a Comment for "How To Put HTML Data Into Header Of Tcpdf?"