PHP mPDF 库无法正确编号偶数/奇数页
我正在尝试用 PHP 生成 PDF。我发现 mPDF 通常效果很好。我遇到的一个问题是我需要能够为某些部分的偶数/奇数页面设置单独的标题。我认为该功能运行不正常。这是我的代码:
// load mPDF
// --------------------------------------------------------------------------
include('mpdf.php');
$mpdf = new mPDF();
// generate a lot of content so it spans multiple pages
// --------------------------------------------------------------------------
$i = 0;
$out = '';
while ($i < 300)
{
$i++;
$out .= '<p>Lorem Ipsum</p>';
}
// set html header for odd pages, write html and output
// --------------------------------------------------------------------------
$mpdf->SetHTMLHeader('ODD {PAGENO}', 'O');
$mpdf->WriteHTML($out);
$mpdf->Output();
当我运行此代码时,它会将“ODD Page 3”或它所在的任何页面...放在每个页面上。不仅仅是奇数页。出于偶数或奇数的目的,它似乎不会将自然损坏的页面视为新页面,而仅将手动损坏的页面视为新页面。如果我运行 AddPage() 函数,它将认为下一组是偶数页。但这可能是 50 次自动分页之后的事。
关于如何让它为实际偶数/奇数页设置不同的标题,而不仅仅是在手动分页符之后,有什么建议吗?
I'm trying to do some PDF generation in PHP. I found mPDF which generally has worked quite well. One problem I'm having though is that I need to be able to set separate headers for even/odd pages for some sections. I don't think the function is working right. Here's my code:
// load mPDF
// --------------------------------------------------------------------------
include('mpdf.php');
$mpdf = new mPDF();
// generate a lot of content so it spans multiple pages
// --------------------------------------------------------------------------
$i = 0;
$out = '';
while ($i < 300)
{
$i++;
$out .= '<p>Lorem Ipsum</p>';
}
// set html header for odd pages, write html and output
// --------------------------------------------------------------------------
$mpdf->SetHTMLHeader('ODD {PAGENO}', 'O');
$mpdf->WriteHTML($out);
$mpdf->Output();
When I run this code it puts "ODD Page 3" or whatever page it's on... on every page. Not just the odd pages. It seems to not consider naturally broken pages as new pages for the purposes of even or odd, only manually broken ones. If I run the AddPage() function it will consider the next group an even page. But that could be 50 auto page breaks later.
Any suggestions on how to get it to set different headers for actual even/odd pages, not just after manual page breaks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记写
$mpdf->mirrorMargins = 1;
这是您的工作示例
参考:
setHTMLHeader
your forget to write
$mpdf->mirrorMargins = 1;
here is your working example
Reference:
setHTMLHeader