Sumant Bag
Sumant Bag

Reputation: 37

Why is the mPDF WriteHTML text coming over the header and overflowing to the footer section?

Why are contents inside the WriteHTML part overlapping 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.

Upvotes: 1

Views: 1558

Answers (2)

Patrick Janser
Patrick Janser

Reputation: 4244

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.

I also noticed that some mPDF variables can be used to change the behavior of margins. Typically setAutoTopMargin can be set to pad or stretch so that the top margin gets automatically changed if the header is to big.

Upvotes: 1

Sumant Bag
Sumant Bag

Reputation: 37

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

This single line solved my problem.

Upvotes: 0

Related Questions