Home > front end >  Why is the mPDF WriteHTML text coming over the header and overflowing to the footer section?
Why is the mPDF WriteHTML text coming over the header and overflowing to the footer section?

Time:01-13

Why my contents inside the WriteHTML part overlaping with the header and footer section ? enter image description here

My code is as follows :

<?PHP
  require_once __DIR__ . '/vendor/autoload.php';
  $mpdf = new \Mpdf\Mpdf();

  // Define the Header/Footer before writing anything so they appear on the first page
  $mpdf->SetHTMLHeader('
  <div style="text-align: right; font-weight: bold; background-color: coral;">
    My document
    <be>
    Go to HELL !
    <hr>
  </div>');

  $mpdf->SetHTMLFooter('
  <table width="100%" style="background-color: coral;">
  <tr>
    <td colspan="3">Another Section</td>
  </tr>
  <tr>
    <td colspan="3">Another Section</td>
  </tr>
  <tr>
    <td width="33%">{DATE j-m-Y}</td>
    <td width="33%" align="center">{PAGENO}/{nbpg}</td>
    <td width="33%" style="text-align: right;">My document</td>
  </tr>
  </table>');

  $mpdf->WriteHTML('Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World<br>Hello World<br>Hello World<br>Hello World<br>Hello 
  World<br>Hello World');

  $mpdf->Output();
?>

I want the "Hello World" text to reside inside the white portion that lies between the header and the footer, despite of the header's and footer's height. Please help me out in fixing this issue with mPDF with PHP. It's very urgent.

CodePudding user response:

Looking at the documentation about margins it says "If you specify a header that extends further down the page than the margin-top, then the header and main text will overlap.".

So I would just modify the document margins until you get what you desire.

CodePudding user response:

$mpdf->AddPage('P','','','','',15,15,30,30,10,10);

This single line solved my problem.

  •  Tags:  
  • Related