如果内容重叠,如何在下一页推送页脚?

问题描述 投票:0回答:1

我有一个HTML文档,我想用Mpdf 7版将其转换为PDF。

HTML结构是。

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

而CSS是:

<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>

里面是: <section> 我有一个运行时生成行的表。

我的PHP代码非常基本

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

在少行或多行的情况下,一切都很好,但在某些情况下,会发生最后一行与页脚重叠的情况。

我想在这种情况下把页脚推到下一页的底部。

我试过用以下方法添加页脚 $pdf->SetHTMLFooter() 并在N行后动态添加一个页面,但结果不是很准确,因为有些行可能是多行。$pdf->setAutoBottomMargin = 'stretch' 但没有任何变化。

有什么建议吗?谢谢。

php mpdf
1个回答
0
投票

html代码

  <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;
}

自定边线

php代码

   $pdf = new \Mpdf\Mpdf();
    $html = file_get_contents('path');
    $pdf->writeHTML($html);
    $pdf->Output();
© www.soinside.com 2019 - 2024. All rights reserved.