简体   繁体   English

将图像添加到dompdf

[英]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. 如果PHP html的表文本(内容)过长,则图像被隐藏(在这种情况下),我想中断页面,然后将图像添加到新页面的底部。
  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. 我也一直尝试使用https://code.google.com/p/cleanstickyfooter/之类的标头/底部CSS,但是上述方法可以正常工作,期望刚才描述的问题。 THE HTML is simple tables with a width of 100%... HTML是宽度为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? 我想我可以通过在图像的高度上添加一个空div来解决第一个问题,现在我只想将其添加到最后一页上。

Inline script is rendered starting with the page dompdf is currently laying out. 从dompdf当前正在布局的页面开始呈现内联脚本。 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. 如果您只想将图像应用于文档的末尾,则可以将脚本重新定位到HTML内容的末尾。

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() ). 另外,如果只需要将图像应用于最后一页,则不需要使用分离的对象( $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. 最后,如果您使用的是dompdf 0.6.0(当前为Beta),则可以跳过内联脚本并仅定位图像。 Positioned content is also rendered starting with the page dompdf is currently laying out. 定位内容也从dompdf当前正在布局的页面开始呈现。 So you can also get the desired image layout adding the following to the bottom of your HTML content: 因此,您还可以获得所需的图像布局,将以下内容添加到HTML内容的底部:

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

You must, of course, generate the required HTML for the image. 当然,您必须为图像生成所需的HTML。 I'm assuming you're already doing that since you're accessing the $id global variable in the inline script. 我假设您已经在执行此操作,因为您正在访问内联脚本中的$id全局变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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