set background image to a specified page with @page selector

1.2k views Asked by At

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...

1

There are 1 answers

0
tirdadc On BEST ANSWER

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.