Wicked_pdf: UTF-8 not working on Heroku

Created on 9 Jan 2013  路  7Comments  路  Source: mileszs/wicked_pdf

I read several posts on UTF-8 and it's still not working for me on Heroku.

When the PDF generates, it creates boxes where the characters would be (Chinese characters in this case). However, when i run the PDF with ?debug=1, I can see the characters.

I've tried the following:

Using wicked_pdf-0.9.0

Downgraded to wkhtmltopdf 0.9.9 (filename: wkhtmltopdf-amd64)

Here's my config file

WickedPdf.config = {
    :exe_path => Rails.root.join('bin', ENV['WICKEDPDF_FILE']).to_s,
    :layout => 'layouts/pdf.html',
    :orientation => 'Landscape',
    :page_size => 'Letter',
    :disable_internal_links => true,
    :disable_external_links => true
}

Here's my controller code

format.pdf do
        render :pdf => "SMT_Tour_v"+Time.now.strftime("%b_%d_%Y"), :encoding => 'UTF-8', :formats=>[:html], :show_as_html => params[:debug].present?
      end

Here's what I have in my pdf.html

<meta content="text/html; charset=utf-8" http-equiv="content-type">
documentation

Most helpful comment

BTW, not having native fonts on the server normally isn't an issue for websites, since they are usually installed as part of the OS of systems that access the site.

However, WickedPdf uses wkhtmltopdf to render the website in a headless browser on the server, and since the font's aren't installed on the OS locally, they don't render. That's why more fonts are needed on the server in this scenario.

All 7 comments

Any ideas?

I'm not able to reproduce this problem as long as that meta tag is there:

http://wickedpdftest.herokuapp.com/tests/unicode.pdf

Are you using 'wkthmltopdf-binary' along with 'wicked_pdf' in your Gemfile?

Can you post some of the characters that are giving you trouble?

I know this is closed, but I'm experiencing this problem on heroku but not in my dev environment. I'm not using the wkthmltopdf-binary gem. Should I be?

Can you post some of the characters that are giving you trouble?

Hello. We're having trouble with Japanese characters which end up appearing as rectangles. We're using both gems and defining the UTF-8 meta tag. This only happens on Heroku and not locally.

Gem versions:

    wicked_pdf (1.2.2)
    wkhtmltopdf-binary (0.12.3.1)

Heroku doesn't have native fonts for many languages installed on it's dynos, so you'll need to either provide them yourself in your app bundle in a .fonts directory at the top of your repo, or use web-fonts.

Here's an article on providing .ttf files in the .fonts dir: https://elspoono.wordpress.com/2011/11/29/installing-fonts-on-heroku-for-nodejs/

Here's an article on embedding web fonts: http://www.apleroy.com/posts/custom-pdf-fonts-with-wicked_pdf-and-heroku
(BTW, this has you manually base64 encode the font, but there is a wicked_pdf_asset_base64() helper you can use instead now)

Thanks for the pointers! It appears there are buildpacks too having just Googled around. Thanks again

BTW, not having native fonts on the server normally isn't an issue for websites, since they are usually installed as part of the OS of systems that access the site.

However, WickedPdf uses wkhtmltopdf to render the website in a headless browser on the server, and since the font's aren't installed on the OS locally, they don't render. That's why more fonts are needed on the server in this scenario.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgdosen picture dgdosen  路  5Comments

douglasep picture douglasep  路  4Comments

VladFarion picture VladFarion  路  4Comments

andheiberg picture andheiberg  路  3Comments

panniru picture panniru  路  5Comments