rails, wicked-pdf gem and é à ö characters showing incorrectly
Asked Answered
I

4

6

When I generate a PDF with text containing characters such as é è à and so on I do get funny characters instead.

I know this must be related to encoding.

I did try force_encoding("UTF-8") on the string with those characters with no success.

joel

Illinium answered 5/2, 2012 at 23:40 Comment(0)
N
8

Add <meta charset="UTF-8"> to the top of your HTML view or in the head of your layout.

Nerti answered 9/3, 2012 at 1:35 Comment(0)
U
8

You can pass as option:

encoding: 'utf8'
Ullund answered 20/9, 2012 at 6:15 Comment(0)
S
5

You can also add it as an option in the wickedpdf

 WickedPdf.new.pdf_from_string(
    render :pdf => "Paper",
    :template => "paper/paper.html",
    :page_size => 'A4',
     formats: :html, encoding: 'utf8',
    :margin => {:top => 40}
  )
Sanson answered 15/7, 2014 at 12:14 Comment(1)
Thanks for this. Wicked's documentation for pdf_from_string doesn't really hint that you can pass options like this (sans controller/view). Eg this worked for me: pdf = WickedPdf.new.pdf_from_string(html, encoding: 'utf8')Geode
C
0

To solve this, add the following line at the beginning of your view:

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

You can refer this link - https://github.com/mileszs/wicked_pdf/issues/35 for more details.

Conform answered 21/4, 2014 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.