Wicked_pdf: Background image used as watermark not working on production

Created on 11 Feb 2015  路  7Comments  路  Source: mileszs/wicked_pdf

I'm using a background image into body for watermark, it works perfect in development, but not in production server, this is the style:
body.watermark{
background-image: url(<%= asset_data_uri 'mylogo.png' %>);
background-repeat:repeat-y;
background-position: center 250px;
background-attachment:fixed;
background-size:100%;

}

the style is into a file.css.erb

I also have tried an absolute path like (also change the image format)
background-image: url('images/mylogo.jpg');

I've set the property no-background to false..

Bassically I've tried everything but still not working into production server.

I'm using wkhtmltopdf 0.12.1 (with patched qt), Rails 4.1.0.

Most helpful comment

This worked for me in Rails 5 - in development and production after I changed my .css file to .css.scss. Hope it helps

background-image: asset-data-url("pdf_watermark.png");

All 7 comments

wkhtmltopdf will need a _full_ file path or URI, since it needs to gather everything from a static file.

Try with a full filesystem path:

background-image: url('<%= Rails.root.join('public','images','mylogo.jpg') %>');

or a full URI with host and protocol:

background-image: url('http://yourdomain.com/mylogo.jpg');

Or by base64-encoding your assets with a helper like this:

def asset_data_base64(path)
  asset = Rails.application.assets.find_asset(path)
  throw "Could not find asset '#{path}'" if asset.nil?
  base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
  "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
end
background-image: url('<%= asset_data_base64('images/mylogo.jpg') %>');

Let me know how it goes!

@unixmonkey still not working on production server :(

Are you putting quotes inside the url('') declarations? wkhtmltopdf can be picky about that.

yes.. Is working on development, but not in production.. that's the rare part.

Can you use debug: true, and paste the relevant parts of the html source?

@taniadaniela Did you get things working?

This worked for me in Rails 5 - in development and production after I changed my .css file to .css.scss. Hope it helps

background-image: asset-data-url("pdf_watermark.png");
Was this page helpful?
0 / 5 - 0 ratings

Related issues

VladFarion picture VladFarion  路  4Comments

lsarni picture lsarni  路  5Comments

EdouardPan picture EdouardPan  路  6Comments

lisamburns picture lisamburns  路  3Comments

dgdosen picture dgdosen  路  5Comments