Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to set header and footer in PDF using mpdf

I have generated a PDF using mpdf library in CodeIgniter. I want to attach header image and footer image with proper margin, I have created one code but header and footer get overlapped.

//controller
$this->load->library('m_pdf');
    $param = '"","A4","","",0,0,100,0,6,3,"L"';
    $pdf = $this->m_pdf->load($param);
    // $pdf->useOddEven = true;

    $pdf->SetHTMLHeader('<img src="' . base_url() . 'custom/Hederinvoice.jpg"/>');

    $pdf->SetHTMLFooter('<img src="' . base_url() . 'custom/footarinvoice.jpg"/>');
    $wm = base_url() . 'custom/Watermark.jpg';
    $pdf->SetWatermarkImage($wm);
    $pdf->showWatermarkImage = true;
      $data['main_content'] = 'dwnld';
    $this->load->view('template', $data);
    $html = $this->load->view('template_pdf', $data, true);
    $this->load->view('template_pdf', $data, true);
    $pdf->WriteHTML($html);
    $pdf->page = 0;
    $pdf->state = 0;
    $pdf->Output($pdfFilePath, "D");

enter image description here

like image 430
Saurabh Gujarani Avatar asked Mar 14 '16 11:03

Saurabh Gujarani


People also ask

How do I add a footer in mPDF?

SetFooter() Set a page footer. Note: This function/method was altered in mPDF 2.2 by capitalising the first letter of the name. As function/method names in PHP have hitherto been case-insensitive, this should not cause any problems, but it is recommended where possible to use the preferred spelling.

How do you add a header and footer to a PDF in HTML?

Or we can load them via HTTP: $client->setHeaderUrl('https://your-domain/footer.html'); $client->setFooterUrl('https://your-domain/header.html'); The following code will make them 0.7' tall: $client->setHeaderHeight('0.7in'); $client->setFooterHeight('0.7in');

How do I change page size in mPDF?

// Define a page size/format by array - page will be 190mm wide x 236mm height $mpdf = new \Mpdf\Mpdf(['format' => [190, 236]]); The format is an array of width and height in millimeters. Save this answer.


1 Answers

 $pdf->SetHTMLHeader('<img src="' . base_url() . 'custom/Hederinvoice.jpg"/>');

    $pdf->SetHTMLFooter('<img src="' . base_url() . 'custom/footarinvoice.jpg"/>');
    $wm = base_url() . 'custom/Watermark.png';

      $data['main_content'] = 'dwnld';
    //$this->load->view('template', $data);
    $html = $this->load->view('template_pdf', $data, true);
    $this->load->view('template_pdf', $data, true);
    $pdf->AddPage('', // L - landscape, P - portrait 
        '', '', '', '',
        5, // margin_left
        5, // margin right
       60, // margin top
       30, // margin bottom
        0, // margin header
        0); // margin footer
    $pdf->WriteHTML($html);

    $pdf->Output($pdfFilePath, "D");

Addpage for to creating page in mpdf and pass parameters of margin top,bottom then we get proper output

like image 140
Saurabh Gujarani Avatar answered Oct 19 '22 23:10

Saurabh Gujarani