Mpdf different header for first page

血红的双手。 提交于 2019-11-28 07:57:04

问题


I am working on quotation software where I am using mpdf for quotation generation using HTML format. Header are set by code below.

$mpdf->SetHTMLHeader($header);
$mpdf=>SetHTMLFooter($footer);

Which applies uniformly to all pages. But I need different header to first page. How should I achieve it?


回答1:


As you wrote, SetHTMLHeader and SetHTMLFooter apply to the entire document. If you want different headers / footers for the first page you will have to remove both

$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);

And do it like so:

  1. In your PDF's HTML code, place right after the <body> tag the different header definitions like so:
<htmlpageheader name="firstpage" style="display:none">
    <div style="text-align:center">First Page</div>
</htmlpageheader>

<htmlpageheader name="otherpages" style="display:none">
    <div style="text-align:center">{PAGENO}</div>
</htmlpageheader>
  1. Set your headers like this (still in you first page's code)
<sethtmlpageheader name="firstpage" value="on" show-this-page="1" />
<sethtmlpageheader name="otherpages" value="on" />

This turns on both headers but on the first page shows the "firstpage" header.

  1. Same goes for footers.


IMPORTANT NOTE:

There are actually a few ways to go about it. They are all documented here. I chose to write here the one I think is the most straight forward and will easily work, but I recommend you read the docs and choose the one that best suits your needs.




回答2:


As Yotam said, there's other ways to acomplish this. If you are using CSS to style your page, as usual, you may find the @page selector useful. It should be something like this:

@page {
    header: html_otherpages;
}

@page :first {
    header: html_firstpage;
}

Hope this helps.

Regards.




回答3:


place right after the <body>

<htmlpageheader name="firstpageheader" style="display:none">
    <div style="text-align:center"> first page header</div>
</htmlpageheader>

<htmlpagefooter name="firstpagefooter" style="display:none">
    <div style="text-align:center">first page footer</div>
</htmlpagefooter>

<htmlpageheader name="otherpageheader" style="display:none">
    <div style="text-align:center"> all page Header</div>
</htmlpageheader>

<htmlpagefooter name="otherpagesfooter" style="display:none">
    <div style="text-align:center">all page footer </div>
</htmlpagefooter>

In CSS use following :

@page {  
    header: html_otherpageheader;
    footer: html_otherpagesfooter;
}

@page :first {    
    header: html_firstpageheader;
    footer: html_firstpagefooter;
}


来源:https://stackoverflow.com/questions/24670208/mpdf-different-header-for-first-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!