Risky leopard
Risky leopard

Reputation: 101

wicked_pdf: UTF-8 encoding issue on production

In my Rails 5 app I use wicked_pdf and wkhtmltopdf-binary gem for generating PDF from HTML. But there is some problem while generating PDF on production. Currency symbol is not displaying properly, but it's working fine in development.

Here is my PDF image.

my production pdf screenshot

My Gemfile looks like this:

gem 'wicked_pdf', '~> 1.1'
gem 'wkhtmltopdf-binary', '~> 0.12.3.1'

My Controller code:

def generate_order
  @order = @user_builder.orders.find(params[:id])
  render pdf: 'billing_pdf',
  layout: 'layouts/pdf.html.erb',
  :show_as_html => params[:debug].present?, #true
  encoding: 'utf8'
end

I tried lots of solutions from Stackoverflow to other similar questions. They all suggested me to add meta in layout file. I also added it in my layout file.

edited

my PDF layout file.

<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title>Billing</title>
</head>
<body>
   <div class='container'>
     <%= yield %>
   </div>
</body>
</html>

I will be really grateful if someone could point out what is going wrong in this case. Thanks in advance.

Upvotes: 2

Views: 1615

Answers (1)

Vasfed
Vasfed

Reputation: 18504

Other that encoding issues (which look to be set up fine, only I'd use Content-Type to be sure) you may be having issues with fonts on production machine.

Things to try:

  1. Rendering other unicode characters, if some them render correctly - it's not an encoding problem
  2. Newer wkhtmltopdf-binary - (0.12.4 at the time), or wkhtmltopdf_binary (other gem, is stale at the moment)
  3. Ensuring production server has fontconfig and libfontconfig installed and set up, also that it contains fonts that you're using
  4. Using webfonts (in my tests a while ago eot format appeared to work, but now woff2 may be better)

Upvotes: 3

Related Questions