简体   繁体   English

使用WKHTMLTOPDF的PDF中未显示背景图片

[英]Background Image not showing in PDF using WKHTMLTOPDF

Scenario : 场景:

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. 我正在使用WKHTMLTOPDF工具生成pdf格式的报告,除背景图像未在生成的PDF中呈现外,其他所有操作都正常,尽管它以HTML格式正确显示。

What i have tried : 我试过的

  • I have changed the format of background image from png to jpg but no Luck. 我将背景图片的格式从png更改为jpg,但是没有运气。

  • I have used the --javascript-delay 5000 code in WKHTMLTOPDF, for waiting to render the image but still no luck. 我已经使用--javascript-delay 5000代码来等待渲染图像,但是仍然没有运气。

Strange Behavior : 奇怪的行为 :

I have one more different image with background and it is showing properly. 我的背景还有另外一张图片,并且显示正确。

My Question : 我的问题 :

What is wrong with this scnerio, As the other image is showing properly with background but not this one ? 此场景有什么问题,因为另一幅图像可以正确显示背景,但不能正常显示? Please help me .Thanks. 请帮助我。谢谢。

Updated : 更新 :

I'm executing the cmd 我正在执行cmd

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

And while executing getting the warnings : 在执行警告时:

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

Used CSS : 二手CSS:

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

I finally figured it out; 我终于想通了; the problem was with my CSS. 问题出在我的CSS上。

I changed it from: 我将其更改为:

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

to: 至:

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

Does your image file name contain whitespaces? 您的图片文件名是否包含空格? If yes, use rawurlencode() function on your file name (not your complete file path) and try. 如果是,请在文件名(而不是完整的文件路径)上使用rawurlencode()函数,然后尝试。

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

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