Reputation: 159
Am using mpdf. I want to set footer with some extra line only on first page. and only page number on second onwaords lines. which we generally follow in continuation sheet concept of letters.
I looked in mpdf manual but seems there is no way for this. Do anybody have solution for this?
Upvotes: 1
Views: 4779
Reputation: 1
First use the following at the beginning inside the body tag like so:
<htmlpagefooter name="firstpage">First page</htmlpagefooter>
<htmlpagefooter name="otherpages">Page {PAGENO} of {nb}</htmlpagefooter>
Then within the content of your first page use this :
<sethtmlpagefooter name="firstpage" value="on" show-this-page="1" />
To allow setting the rest of the pages use this after the content of the second page:
<sethtmlpagefooter name="otherpages" value="on" />
How this works is that the sethtmlpagefooter with the value on serves to notify mPDF when to start using the footer or when to stop at any point within your document, you can therefore use:
<sethtmlpagefooter name="otherpages" value="off" />
To disable the footer rendering at any point within the document. Please note that I use the html tag: <div class="page-break"></div>
with css code .page-break {page-break-before: always; }
To forcefully break the pages of my document therefore controlling which content goes to which page and ultimately controlling when the footer will be displayed for each page.
Here is an example in use:
<html>
<head>
<style>
.page-break {page-break-before: always; }
</style>
</head>
<body>
<htmlpagefooter name="firstpage">First page</htmlpagefooter>
<htmlpagefooter name="otherpages">Page {PAGENO} of {nb}</htmlpagefooter>
<p>Some varying content of my first page.</p>
<p>Some other content still on the first page</p>
<sethtmlpagefooter name="firstpage" value="on" show-this-page="1" />
<div class="page-break"></div>
<p>Some varying content of my second page</p>
<sethtmlpagefooter name="otherpages" value="on" />
<div class="page-break"></div>
<p>This content will show on the third page</p>
</body>
</html>
Upvotes: 0
Reputation: 81
You may control headers and footers of the generated PDF with CSS and the @page model.
See mPDF Documentation about using @page
Here is a very simple CSS and HTML to generate a PDF with different headers and footers for the first and the following pages using @page and named headers and footers:
@page {
header: html_header;
footer: html_footer;
}
@page :first {
header: html_header-firstpage;
footer: html_footer-firstpage;
}
<htmlpageheader name="header-firstpage" style="display: none;">
<p>This header appears on the first page only</p>
</htmlpageheader>
<htmlpageheader name="header" style="display: none;">
<p>This header appears on the following pages</p>
</htmlpageheader>
<htmlpagefooter name="footer-firstpage" style="display: none;">
<p>This footer appears on the first page only</p>
</htmlpageheader>
<htmlpagefooter name="footer" style="display: none;">
<p>This footer appears on the following pages</p>
</htmlpageheader>
<h1>The content of the document</h1>
<p>Yadda... yaddaa... blah... blahh</p>
The space before ":first" selector in the CSS is needed.
Upvotes: 1