简体   繁体   中英

Add image on to dompdf

  <script type="text/php"> 
if(isset($pdf)){ 
        $w = $pdf->get_width(); 
        $h = $pdf->get_height(); 

        $footer = $pdf->open_object(); 

          global $id


        $pdf->image('s/'.$id.'-here.jpg', "jpg", 0, $h - 279, 611, 279); 


        $pdf->close_object(); 

        $pdf->add_object($footer, "all"); 
} 
</script> 

I am trying to add a footer similar image on the end of the page and this is the only code I actually managed to have the picture on the bottom, however I got two problems now:

  1. If the tables text (content) of the PHP html goes to long it's hidden by the image (in this case) i want to break the page and then add the image in the bottom on the new page.
  2. How can I make it's only added on the last page if there are more than one by simply the dynamic output I am doing on a table.

Anyway I can overcome the problems above with simply this code? I've been trying using header/bottom CSSes like https://code.google.com/p/cleanstickyfooter/ as well but the method above is working expect the sligh issues just described. THE HTML is simple tables with a width of 100%...

QUICK update (though)

I think I can solve the first issue by adding a empty div with a set height of the image, now I would only want to add this onto the last page... How?

Inline script is rendered starting with the page dompdf is currently laying out. If you want your image to apply only to the end of the document you can just relocate the script to the end of the HTML content.

Also, if you only need to apply the image to the last page you don't need to use detached objects ( $pdf->open_object() / $pdf->close_object() / $pdf->add_object() ). The purpose of detached objects is to provide a means of reusing content. So your inline script can be as simple as:

<script type="text/php"> 
if(isset($pdf)){ 
  $w = $pdf->get_width(); 
  $h = $pdf->get_height(); 
  global $id
  $pdf->image('s/'.$id.'-here.jpg', "jpg", 0, $h - 279, 611, 279); 
} 
</script> 

Lastly, if you're using dompdf 0.6.0 (currently in beta) you can skip the inline script and just position the image. Positioned content is also rendered starting with the page dompdf is currently laying out. So you can also get the desired image layout adding the following to the bottom of your HTML content:

<div style="position: absolute; bottom: 10px;">
  <img src="s/$id-here.jpg">
<div>

You must, of course, generate the required HTML for the image. I'm assuming you're already doing that since you're accessing the $id global variable in the inline script.

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