0
votes

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.

What i have tried :

  • 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.

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

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

And while executing getting the warnings :

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

Used CSS :

background: transparent url(images/abc.png) no-repeat scroll 0% 0% / 100% 100%;
2
Just in case, you are sure the path to the background is correct?entiendoNull
@entiendoNull , yes I'm pretty much sure that image path is correct and it is rendering properly on HTML.Harshal Mahajan
Try adding the complete path to where the image file is located instead of a relative one and see if that helps...entiendoNull
@Downvoters , Please explain the reason.Harshal Mahajan
@entiendoNull I'm giving the exact relative path like http://example.com/assets/images.abc.pngHarshal Mahajan

2 Answers

3
votes

I finally figured it out; the problem was with my 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%;
1
votes

Does your image file name contain whitespaces? If yes, use rawurlencode() function on your file name (not your complete file path) and try.