Wicked_pdf: Wickedpdf Encoding

Created on 12 Oct 2015  路  4Comments  路  Source: mileszs/wicked_pdf

Hi,

I am having the problem of displaying Japanese characters in my pdf. It displays very well in the view files. I am using pdf_from_string command from wicked pdf.
I've tried adding
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
in my view files but still doesn't work

Moreover, I also added
:encoding => 'UTF-8' In the options

Here is the code
Controller

html = render_to_string(:action => :print,:layout => false, encoding: "ISO-8859-15")
pdf = WickedPdf.new.pdf_from_string(html,:encoding => 'UTF-8',:page_size => 'A4',:footer => { :right => '[date] [time] - page [page] of [topage]', :font_size => '6' })
send_data(pdf,
  :filename    => "print.pdf",
  :encoding => "utf8",
  :disposition => 'attachment')

View

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  </head>
  <body>
    <!-- Japanese chars here --> 
   </body>
</html>
fonts

Most helpful comment

I had a same your problem and i took a lot of times to find it, but i solved it successfully.
Your problem is missing Japanese fonts. And i think you should do as follow:

Step1: wget http://dl.ipafont.ipa.go.jp/IPAexfont/IPAexfont00301.zip
Step2: unzip IPAexfont00301.zip
Step3: ls -l IPAexfont00301/*ttf

Step4: mkdir -p /usr/share/fonts/japanese/TrueType
Step5: mv -i IPAexfont00301/*ttf /usr/share/fonts/japanese/TrueType/
Step6: ls -l /usr/share/fonts/japanese/TrueType/

Step7: fc-cache -fv
Step8: fc-list | grep IPA

Step9: Restart rails server and see the result

Here is document:
http://qiita.com/metheglin/items/bb88aa25eae250bfa2a2#3-1

And link to download Japanese fonts:
http://ipafont.ipa.go.jp/node26#jp

All 4 comments

Can you include some of the Japanese characters so I could try and reproduce this?

My first thought is maybe the system you are generating the files on may not have Japanese fonts installed.

It's Japanese Yen symbol 楼. I was trying to make a sales report in my e-commerce website.
Thank you for your advise. I will try to find it out using your suggestion.

I had a same your problem and i took a lot of times to find it, but i solved it successfully.
Your problem is missing Japanese fonts. And i think you should do as follow:

Step1: wget http://dl.ipafont.ipa.go.jp/IPAexfont/IPAexfont00301.zip
Step2: unzip IPAexfont00301.zip
Step3: ls -l IPAexfont00301/*ttf

Step4: mkdir -p /usr/share/fonts/japanese/TrueType
Step5: mv -i IPAexfont00301/*ttf /usr/share/fonts/japanese/TrueType/
Step6: ls -l /usr/share/fonts/japanese/TrueType/

Step7: fc-cache -fv
Step8: fc-list | grep IPA

Step9: Restart rails server and see the result

Here is document:
http://qiita.com/metheglin/items/bb88aa25eae250bfa2a2#3-1

And link to download Japanese fonts:
http://ipafont.ipa.go.jp/node26#jp

@khanhpham1990
This URL http://dl.ipafont.ipa.go.jp/IPAexfont/IPAexfont00301.zip is not working anymore. Therefore, we need to use this one wget https://oscdl.ipa.go.jp/IPAexfont/IPAexfont00301.zip.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomasbalsloev picture thomasbalsloev  路  3Comments

VladFarion picture VladFarion  路  4Comments

douglasep picture douglasep  路  4Comments

netwire88 picture netwire88  路  7Comments

supriyas12 picture supriyas12  路  4Comments