dtrt2368 2013-08-25 15:13
浏览 59

将图像添加到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?

  • 写回答

1条回答 默认 最新

  • dqwp81696 2013-09-01 18:44
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大