本文介绍了如何通过dompdf提供PDF背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Dompdf将Html Page转换为PDF。作为客户的要求pdf文件的背景应该有水印图像。我在编码方面尝试了很多方法,也有不同的css风格,但没有帮助。有人有任何想法吗?请帮帮我。

I m using Dompdf to convert Html Page to PDF. As client's requirement pdf should have watermark image at background of document. I have tried many ways in coding and also differnt css style but its not helpful. Is anybody has any idea about it? please Help me out.

推荐答案

哪个版本的DOMPDF?使用0.6.0版本,您可以使用固定位置元素作为水印。这是一个文档外壳:

Which version of DOMPDF? With the 0.6.0 release you could use a fixed-position element to act as a watermark. Here's a document shell:

<html>
  <head>
    <style>
      #watermark { position: fixed; bottom: 0px; right: 0px; width: 200px; height: 200px; opacity: .1; }
    </style>
  </head>
  <body>
    <div id="watermark"><img src="http://code.google.com/p/dompdf/logo" height="100%" width="100%"></div>
  </body>
</html>

请参阅此处的示例:

开0.5.1你可以在主体上使用背景图像风格声明。您对样式的控制较少,因此您需要确保图像的格式与文档中的显示格式完全相同,具体涉及大小和不透明度。还有其他一些问题,但这确实奏效。这是一个文档外壳:

On 0.5.1 you could use the background-image style declaration on the body. You have less control over the styling, so you'll want to make sure the image is formatted exactly how it should appear in the document, specifically related to size and opacity. There are other issues, as well, but this does work. Here's a document shell:

<html>
  <head>
    <style>
      body { background-image: url(http://www.wolfsrainfans.com/wp-content/uploads/2011/04/Wolfs_Rain__Taboe_by_Nizira_Hathor.png); background-position: bottom right; background-repeat: no-repeat; }
    </style>
  </head>
  <body>
  </body>
</html>

请参阅此处的示例:

这篇关于如何通过dompdf提供PDF背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 15:30