Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf background-image problems

I'm using wkhtmltopdf in a Rails app and trying to set a border by placing an image with just borders as the background-image for another. (I'm doing this because box-shadow is not working for wkhtmltopdf). This shows up fine in the HTML view, but in the pdf it doesn't work. My CSS is here:

.box{ 
  background-image: url('/assets/posts/background_border.jpg'); 
  background-repeat: no-repeat; 
  height: 100px; 
  width: 100px; 
}

Please let me know how to solve this. Thanks!

like image 251
user3477051 Avatar asked Nov 15 '14 02:11

user3477051


2 Answers

Make the URL for the background image absolute.

background-image: url('http://localhost:8080/assets/posts/background_border.jpg'); 
like image 143
Interlated Avatar answered Oct 01 '22 00:10

Interlated


I had the same problem and finally i solved it. I get

 Exit with code 1 due to network error: ContentNotFoundError

from wktohtml

To solve just remove quote from url declaraion, absolute url is also required. So change

 background-image: url('/assets/posts/background_border.jpg')

To

  background-image: url(http://absolute_url_to_image_without_quote)
like image 29
Piotr Galas Avatar answered Oct 01 '22 00:10

Piotr Galas