Search code examples
javascriptphppdf-generationbackground-imagewkhtmltopdf

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.

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%;

Solution

  • 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%;