【问题标题】:MPDF adding a header and footer to large htmlMPDF向大型html添加页眉和页脚
【发布时间】:2021-09-24 07:11:20
【问题描述】:

我有一个大的 html 文件。 使用 Mpdf,我输出了一个 pdf,它可以完美地工作,但现在我想为所有页面添加页眉和页脚。

我的 html 文件只定义了一个部分。

这里的 mpdf 是横向模式。

我试试这个:

        $mpdf = new \Mpdf\Mpdf([
            'mode' => 'utf-8',
            'orientation' => 'L'
        ]);

        $mpdf->SetHTMLHeader('<h1>TEST</h1>');
        $mpdf->SetHTMLFooter('<h1>TEST</h1>');
        $mpdf->WriteHTML($html);
        $mpdf->Output($namePDF,'F');

但 pdf 文件中没有显示任何内容...

不知道为什么

【问题讨论】:

    标签: php mpdf


    【解决方案1】:

    试试这个

    <?php
    $mpdf = new \Mpdf\Mpdf();
    
    $mpdf->SetHeader('First section header');
    $mpdf->SetFooter('First section footer');
    $mpdf->WriteHTML('First section text...');
    
    // Set the new Header before you AddPage
    $mpdf->SetHeader('Second section header');
    $mpdf->AddPage();
    
    // Set the new Footer after you AddPage
    $mpdf->SetFooter('Second section footer');
    $mpdf->WriteHTML('Second section text...');
    
    $mpdf->Output();
    

    【讨论】:

    • 但是我不想在 Mpdf 生成的所有页面上添加我想要我的标题的页面我只有一个由我的 html 文件定义的部分。
    • 不适用于旧的 SetHeader 和 SetFooter 方法
    • 使用 SetHeader 可以设置标题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 2012-12-10
    • 2010-12-03
    • 2014-08-17
    • 1970-01-01
    相关资源
    最近更新 更多