I want to set header and footer in PDF using mpdf
29,955
$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
Author by
Saurabh Gujarani
Working as Web Developer having 4+ Years of experience.
Updated on July 09, 2022Comments
-
Saurabh Gujarani almost 2 years
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");
-
Manisha about 5 yearsThanks @saurabh its working for me :$pdf->AddPage('', // L - landscape, P - portrait '', '', '', '', 5, // margin_left 5, // margin right 60, // margin top 30, // margin bottom 0, // margin header 0); // margin footer