简体   繁体   中英

set background image to a specified page with @page selector

i would to create a pdf file from html with mpdf library. i would to set a background image just to 2'nd page of rendered pdf(not all pages). i use the following code:

$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>';

in this code the background image set on all pages of rendered pdf(with @page selector).

how can i set the background image just for one page(2'nd page)? thanks...

According to the documentation , mPDF supports named @page selectors, so you could do this:

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

and then:

div.second {
  page: second;
}

and then your second page should be within a div with a second class. Look at the example given at the link with Chapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM