【问题标题】:mPDF - Header for First Page only but Footer for every pagemPDF - 仅首页的页眉,但每页的页脚
【发布时间】:2014-10-13 07:28:08
【问题描述】:

我只需要为第一页设置页眉,为每一页设置页脚。想不出办法,我已经在寻找解决方案 DAYS 了。目前我的代码是这样的

$mpdf=new mPDF();

$mpdf->useOddEven = true;

$mpdf->SetHTMLHeader('<div style="text-align: right;"><img src="var:images" 
width="80px"/></div>', 'O');

$mpdf->SetHTMLFooter('<div style="text-align: left; font-family: Arial, Helvetica,
sans-serif; font-weight: bold;font-size: 7pt; ">Footer</div>');

$html = 'Content';
$mpdf->WriteHTML($html);
$mpdf->Output();

我已将页眉设置为奇数,但是页眉和页脚都出现在其他奇数页(3、5、7、...页)上。有没有办法只制作页眉首页但页脚出现在每一页?

目前使用 MPDF5.6

【问题讨论】:

    标签: php html pdf mpdf


    【解决方案1】:

    根据文档: https://mpdf.github.io/reference/mpdf-functions/sethtmlheader.html

    第三个参数是:

    write
    If TRUE it forces the Header to be written immediately to the current page. Use if the header is being set after the new page has been added.
    DEFAULT: FALSE
    

    所以..

    $mpdf->SetHTMLHeader('<div style="text-align: right;"><img src="var:images" width="80px"/></div>', 'O', true);
    $mpdf->SetHTMLHeader('');
    $footer = array (
        'L' => array (
          'content' => 'Footer',
          'font-size' => 7,
          'font-style' => 'B',
          'font-family' => 'Arial, Helvetica, sans-serif',
          'color'=>'#000000'
      ),
        'C' => array (
          'content' => '',
          'font-size' => 10,
          'font-style' => 'B',
          'font-family' => 'serif',
          'color'=>'#000000'
        ),
        'R' => array (
          'content' => '',
          'font-size' => 10,
          'font-style' => 'B',
          'font-family' => 'serif',
          'color'=>'#000000'
        ),
    'line' => 1,
    );
    $mpdf->SetFooter($footer);
    

    只有 SetFooter 方法可以为奇偶页的页脚设置。

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多