Question

See, I've been looking for a better option to generate dynamic content in Arabic and Traditional Chinese languages in my web application using the gem Prawn. I tried it with English and German and are working fine. But, Arabic and Chinese are not supported..

After searching a lot, I could see that we can use particular fonts for generating the same. We need to download custom fonts and put in Prawn base directory and after creating a pdf object, we need to add this custom font by the below line:

pdf.font "#{Prawn::BASEDIR}/data/fonts/custom_font.ttf" (Gem directory)

But, with the font types I've tried, I'm not sure whether it is exactly alike the translation I've given in my app using Google translator. For Chinese, it is a big issue.

So, can any one of you suggest how I could get a better font for Arabic and Chinese (freely dowbloadable) and it should also support cross-browsers.

Thank you.

Était-ce utile?

La solution

You could use custom fonts to server your purpose:

For Arabic: you can use trado.ttf

For Chinese: you can use gkai00mp.ttf

Create a folder fonts in your '/app/assets/' path and add it to your asset_path by adding the below line in application.rb,

config.assets.paths << Rails.root.join("app", "assets", "fonts")

And for generating the Arabic/Chinese content in PDF report, please do as below.

pdftable = Prawn::Document.new
if I18n.locale == :ar
    #pdftable.font "#{Prawn::BASEDIR}/data/fonts/trado.ttf"
    pdftable.font Rails.root.join('app', 'assets', 'fonts', 'trado.ttf')
    pdftable.text_direction = :rtl
elsif I18n.locale == :zh
    #pdftable.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
     pdftable.font Rails.root.join('app', 'assets', 'fonts', 'gkai00mp.ttf')
end

Hope you could generate reports in Arabic/Chinese languages.

Autres conseils

To print Arabic properly, you will need to use the following gem to transform the arabic letters into their connected readable form:

https://github.com/staii/arabic-letter-connector

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top