本文介绍了mPDF-仅首页的页眉,但每页的页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要为FIRST页面设置页眉,为每个页面设置页脚.找不到办法,我已经在寻找解决方案DAYS.目前,我的代码是这样的

I need to set the header for FIRST page only and the footer for every page. Can't figure a way and I've been search for the solution DAYS already. Currently my code goes like this

$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,...页)上.有没有办法只使页眉成为第一页,而页脚却出现在每一页中?

I've set the header to Odd however, both header and footer appears on other odd page (3, 5, 7,... page). Is there a way to make the header first page only but the footer appears in every page?

当前正在使用MPDF5.6

Currently using MPDF5.6

推荐答案

根据文档: 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

SO ..

$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方法可以为ODD&偶数页面.

Only the SetFooter Method can set for the footer for both ODD & EVEN pages.

这篇关于mPDF-仅首页的页眉,但每页的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:37