Php mPDF未在新页面上添加页眉/页脚
基本上,页眉和页脚仅显示在第一页和手动断开页面后的第一页上 但由于HTML内容过长,页眉和页脚不会显示在任何其他自然延续的页面上。(即没有手册的地方)Php mPDF未在新页面上添加页眉/页脚,php,mpdf,Php,Mpdf,基本上,页眉和页脚仅显示在第一页和手动断开页面后的第一页上 但由于HTML内容过长,页眉和页脚不会显示在任何其他自然延续的页面上。(即没有手册的地方) Page Hader 版权所有布拉布拉1999- 页眉+页脚将显示在此页面上 <sethtmlpageheader name="header" page="all" value="on" show-this-page="1" /> <sethtmlpagefooter name="footer" page="all" valu
Page Hader
版权所有布拉布拉1999-
页眉+页脚将显示在此页面上
<sethtmlpageheader name="header" page="all" value="on" show-this-page="1" />
<sethtmlpagefooter name="footer" page="all" value="on" />
<p>(PDF cover)</p>
<h1>Report</h1>
(PDF封面)
报告
页眉+页脚将显示在第一页上,但不会显示在后续页面上
<pagebreak />
<sethtmlpageheader name="header" page="all" value="on" show-this-page="1" />
<sethtmlpagefooter name="footer" page="all" value="on" />
LONG HTML CONTENT
THAT EXCEEDS PAGE SIZE
长HTML内容
这超出了页面大小
如果在样式中使用@page,删除@page可以解决问题。这就是我所拥有的,也是对我有用的。你可以像这样添加@page:
@page {
header: header_name;
footer: footer_name;
}
我希望这是有用的在这里,我为您提供了一个解决问题的代码片段
<?php
$mpdf = new mPDF();
$mpdf->useOddEven = 1; // Use different Odd/Even headers and footers and mirror margins
// Define the Headers before writing anything so they appear on the first page
$mpdf->SetHTMLHeader('<div style="text-align: right; font-weight: bold;">My document</div>','O');
$mpdf->SetHTMLHeader('<div style="border-bottom: 1px solid #000000;">My document</div>','E');
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">{DATE j-m-Y}</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">My document</td>
</tr></table>
'); // Note that the second parameter is optional : default = 'O' for ODD
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">My document</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">{DATE j-m-Y}</td>
</tr></table>
', 'E');
$mpdf->WriteHTML('Hallo World');
$mpdf->Output();
@page没有解决我的问题。因此,经过多次搜索,我找到了问题的解决方案。在这里,我回答了你的问题。如果你使用@page,请参阅Giovani Generali的答案,因为它对于这种情况是正确的。
<?php
$mpdf = new mPDF();
$mpdf->useOddEven = 1; // Use different Odd/Even headers and footers and mirror margins
// Define the Headers before writing anything so they appear on the first page
$mpdf->SetHTMLHeader('<div style="text-align: right; font-weight: bold;">My document</div>','O');
$mpdf->SetHTMLHeader('<div style="border-bottom: 1px solid #000000;">My document</div>','E');
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">{DATE j-m-Y}</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">My document</td>
</tr></table>
'); // Note that the second parameter is optional : default = 'O' for ODD
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;"><tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">My document</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">{DATE j-m-Y}</td>
</tr></table>
', 'E');
$mpdf->WriteHTML('Hallo World');
$mpdf->Output();