mPDF - 仅限第一页的页眉,但每页的页脚

时间:2014-08-20 03:24:02

标签: php html pdf mpdf

我需要设置FIRST页面的标题和每页的页脚。无法想办法,我一直在寻找解决方案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();

我已将标题设置为Odd,但页眉和页脚都显示在其他奇数页面上(3,5,7,...页面)。有没有办法只将页眉设为第一页,但页脚出现在每个页面中?

目前正在使用MPDF5.6

1 个答案:

答案 0 :(得分:2)

根据文件: http://mpdf1.com/manual/index.php?tid=150

第三个参数是:

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和amp;设置页脚。即使页面。