shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

problem rendering document with text in Japanese in utf-8 #43

Closed tenzan closed 10 years ago

tenzan commented 11 years ago

require 'rghost' include RGhost

doc = Document.new :paper => :A4, :encoding => 'utf-8'

doc.text_in :x => 5, :y=> 28, :write => "東京"

doc.render :pdf, :filename => "file.pdf"

When I ran the code above I got errors:

/Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ruby_ghost_config.rb:78:in encode': U+6771 from UTF-8 to ISO-8859-1 (Encoding::UndefinedConversionError) from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ruby_ghost_config.rb:78:inblock in module:Config' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ruby_to_ps.rb:16:in call' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ruby_to_ps.rb:16:inpack_string' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ruby_to_ps.rb:62:in string_eval' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/text_in.rb:40:inps' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ps_object.rb:41:in set' from /Users/askar/.rvm/gems/ruby-2.0.0-p195/gems/rghost-0.9.3/lib/rghost/ps_facade.rb:141:intext_in' from rghost.rb:6:in `

'

jgburet commented 11 years ago

Same problem for all languages with no letter (chinese, korea, whatever else).

You can skirt this error with : "".force_encoding('ISO-8859-1') when saving your string.

Rendering will sucks if your font is not managing these symbols.

Another error will pop if you are using a font that can manage symbols (ex : BabelStoneHan.ttf) : can't convert String into Hash

What I'll say is probably stupid but, imo it comes from the fact text-methods are trying to convert everything in iso-8859-1 instead of keeping infos in their encoding.

tenzan commented 10 years ago

Thanks for heads up.