user2244804
user2244804

Reputation:

TCPDF header issue

I want to create pdf with my own html , header and footer.

Here is what I tried but it do not print. It just shows me same html

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$my_header = '<div style="background:#2185E7;color:#fff;padding:5px;overflow:hidden;  width:786px;" class="blue_line">
<h3 style="margin-bottom: 0;    margin-top: 0;padding-left: 17px;text-align:  left; white-space: nowrap;float:left;">Royal Home Real Estate. RERA ORN: 2533</h3>
<p style="margin-bottom: 0; margin-top: 0; padding-right: 14px;text-align: right;   white- space: nowrap;float:right;" class="pdf_number">321 32111 4</p>
</div>';
$pdf->setHeaderData('', PDF_HEADER_LOGO_WIDTH, html_entity_decode($my_header, ENT_QUOTES, 'UTF-8'), '');

Upvotes: 1

Views: 2074

Answers (1)

EPB
EPB

Reputation: 4029

You'll need to write a class that extends TCPDF with it's own Header method, kind of like below. (btw, if your content ends up being all white, change background:#2185E7; to background-color:#2185E7;) You'll likely want to play around with margins and positioning.

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $this->SetFont('helvetica', 12);
        $this->WriteHTML('<div style="background-color:orange">This is HTML!</div>');
    }
}

For more details see TCPDF example 3 on the TCPDF website or in your TCPDF examples folder.

Upvotes: 1

Related Questions