使用 WKHTMLTOPDF 的 PDF 中不显示背景图像

Background Image not showing in PDF using WKHTMLTOPDF

场景:

I'm generating the Report in pdf format using WKHTMLTOPDF tool, Every thing works fine except the background image is not rendering in generated PDF.While it is showing properly in HTML format.

我试过的:

  • I have changed the format of background image from png to jpg but no Luck.

  • I have used the --javascript-delay 5000 code in WKHTMLTOPDF, for waiting to render the image but still no luck.

奇怪的行为:

I have one more different image with background and it is showing properly.

我的问题:

What is wrong with this scnerio, As the other image is showing properly with background but not this one ? Please help me .Thanks.

更新:

I'm executing the cmd

My Code: wkhtmltopdf http://example.com/renderpdf sample.pdf

And while executing getting the warnings :

QFont::setPixelSize: Pixel size <= 0 (0)

二手 CSS :

background: transparent url(images/abc.png) no-repeat scroll 0% 0% / 100% 100%;

您的图像文件名是否包含空格?如果是,请在您的文件名(不是您的完整文件路径)上使用 rawurlencode() 函数并尝试。

我终于想通了;问题出在我的 CSS.

我将其更改为:

background: transparent url(http://example.com/abc.png) no-repeat scroll 0% 0% / 100% 100%;

至:

background:url(http://example.com/abc.png) no-repeat; background-size:100%` 100%;