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");
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.
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');
// 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.
$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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With