使用@page选择器将背景图像设置为指定页面

问题描述 投票:2回答:1

我将使用mpdf库从html创建pdf文件。我想将背景图像设置为渲染的pdf的第二页(并非所有页面)。我使用以下代码:

$mpdf=new mPDF(''); 
$html = '
    <body>
    <style>
      @page {
       background: url("../mpdf60/bg1.jpg") 50% 0 no-repeat;
     }
    </style>

    <div style="margin-bottom:50px">&nbsp;</div>
    <div align="center" style=" margin-bottom:350px"><img src="../mpdf60/pdffirst1.jpg" height="100" width="190" alt=""></div>

    <pagebreak />
    <div>
    </div>
    </body>';

在此代码中,背景图像设置在渲染的pdf的所有页面上(带有@page选择器)。

我如何仅为一页(第二页)设置背景图像?谢谢...

php html pdf selector mpdf
1个回答
3
投票

根据documentation,mPDF支持命名的@页面选择器,因此您可以这样做:

<style>
  @page second {
    background: url("../mpdf60/bg1.jpg") 50% 0 no-repeat;
  }
</style>

然后:

div.second {
  page: second;
}

然后,您的第二页应位于具有second类的div内。查看带有Chapter链接的示例。

© www.soinside.com 2019 - 2024. All rights reserved.