django-wkhtmltopdf
django-wkhtmltopdf copied to clipboard
background-image not rendered
Hi,
Im working on incorporating wkhtmltopdf into our django application and am using django-wkhtmltopdf. Ive gotten just about everything to work, but got stuck on background images. They show up fine in the browser and also on pdf's when generated through wkhtmltopdf on command line. However, django-wkhtmltopdf won't show the image at all. The pdf just shows a blank background, without any error messages.
I've tried numerous ways of declaring the image in my css, but I just cant seem to make it work. It took me some time to figure out how to get static files to work in general, but nothing of what works for that has any effect on this. Even using a picture from the internet gives the exact same problem, leading me to believe it's not a problem with the url or static files.
Here's an example of the relevant css:
.my-div-with-background { background-image: url({% static 'path/to/img' %}); background-repeat: no-repeat; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }
Let me know if any additional information is needed, thanks in advance.
I have found that sometimes the issue is actually with "load" times. In many cases, it helps to add the argument 'javascript-delay': 500 to the cmd_options dictionary. This is meant to give JavaScript time to modify the page appearance before generating the PDF, but it also allows time for images to load over the internet.
Note: that time is in milliseconds. On one particular view, I had to up it 2000 (or 2 seconds) because it loads 50 pages worth of images.
I'm facing the same problem, and the load time doesn't seem to solve it.
Got the same problem. Adding arbitrarily long wait times does not seem to solve the issue either. Any ideas what could be causing this?
The same happens to me, but I noticed that when a normal image is loaded, static is resolved differently than the background image. I.E. in my case I have:
{% load static %} < link rel="stylesheet" type="text/css" media="screen" href="{% static 'css/main.css' %}" / > < div class="container" style="background: #ffffff url({% static 'icons/bg.jpg' %}) repeat center center;" >
And main.css is resolved to file:///home/javier/proyectos/django/hackaton/staticfiles/css/main.css but for the background I get the error: Warning: Failed to load file:///static/icons/bg.jpg (ignore)
Hope this information helps to solve the bug.