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

时间:2020-05-30 11:06:37

标签: php mpdf

我有一个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',但没有任何改变。

有什么建议吗?谢谢。

1 个答案:

答案 0 :(得分:1)

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();
相关问题