I have a large html file.
With Mpdf, I output a pdf and it perfectly work but now I want to add header and footer to all pages.
I have only one section define by my html file.
Here mpdf is in landscape mode.
I try this :
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'orientation' => 'L'
]);
$mpdf->SetHTMLHeader('<h1>TEST</h1>');
$mpdf->SetHTMLFooter('<h1>TEST</h1>');
$mpdf->WriteHTML($html);
$mpdf->Output($namePDF,'F');
but nothing shown in pdf file...
Can't figure why
My Answer:
You need to use the `SetHTMLHeader()` and `SetHTMLFooter()` methods before calling the `WriteHTML()` method. Also, make sure that your HTML content includes the necessary CSS styles for the header and footer to be displayed correctly.
Here is an example of how you can add a header and footer to your PDF using MPDF:
php
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'orientation' => 'L'
]);
$header = 'Header Content';
$footer = 'Footer Content';
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
$mpdf->WriteHTML($html);
$mpdf->Output($namePDF, 'F');
Make sure to replace `'Header Content'` and `'Footer Content'` with your actual header and footer content. Also, ensure that your HTML content includes the necessary CSS styles for the header and footer to be displayed correctly in the PDF.
Rate this post
5 of 5 based on 7705 votesComments