nulele
nulele

Reputation: 396

How to push footer in next page if content overlaps it

I have an HTML document that I want to transform in PDF with Mpdf version 7.

The HTML structure is:

<header>...</header>
<section>...</section>
<footer>...</footer>

And the CSS is:

<style>
    @page {
        size: 21cm 29.7cm;
        margin: 0.5cm;
        padding: 0;
    }

    section {
        font-family: 'helvetica', sans-serif;
        margin: 0;
        padding: 0;
    }

    table {
        margin: 0;
        padding: 0;
        font-family: 'helvetica', sans-serif;
        border-collapse: collapse;
    }

    header {
        margin-bottom: 10pt;
    }

    footer {
        position: static;
        bottom: 10pt;
        margin: 0;
        padding: 0;
    }
</style>

Inside <section> I have a table with runtime generated rows.

My PHP code is very basic

$pdf = new \Mpdf\Mpdf();
$pdf->writeHTML($html);
$pdf->Output($filepath, 'F');

Everything works well with few rows or many rows but in certain conditions happen that last rows overlap the footer.

I'd like to push the footer on the bottom of the next page when this happens.

I've tried adding footer with $pdf->SetHTMLFooter() and adding a page dynamically after N rows but the result is not very accurate becouse some rows may be multiline. I've also tried $pdf->setAutoBottomMargin = 'stretch' but nothing changed.

Any suggestion? Thanks.

Upvotes: 1

Views: 633

Answers (1)

Hamza T
Hamza T

Reputation: 377

html code

  <htmlpageheader name="header">
       <h1>your header</h1>
   </htmlpageheader>

         <div>
             main body
        </div>

      <htmlpagefooter name="footer">
         <h1>your footer</h1>
      </htmlpagefooter>

CSS

@page 
{
    header: header;
    footer: footer;
    margin-top: 89mm;  
    margin-bottom: 61mm;
}

set your own margine

php code

   $pdf = new \Mpdf\Mpdf();
    $html = file_get_contents('path');
    $pdf->writeHTML($html);
    $pdf->Output();

Upvotes: 2

Related Questions