3
votes

I have a Rails app and I use Prawn gem there. I need to make it to generate pdf with Russian alphabet (mix of Russian and English words, in fact). I did a research and found some time ago it was fairly tricky. What about it now, how do I do that?

def about
    respond_to do |format|
      format.html
      format.pdf do
        pdf = Prawn::Document.new
        pdf.text "не ну ни фига sebe"
        send_data pdf.render
      end
    end
  end
1
Have a try, doesn't matter if it is broken, and put your code in the question. It will be easier to help when we can see how you are using fonts and character encoding (one or both may need to change). - Neil Slater
@NeilSlater, has it helped you? - Alan Coromano
Yes I can get a fault - all Russian alphabet characters appear as underscores. But the good news is that it has the right number of characters, so this is just a font issue (prawn does the right thing with character encoding). - Neil Slater
@NeilSlater, what do I do? I added # encoding: utf-8 to a controller's file, but no luck. - Alan Coromano

1 Answers

5
votes

This is an issue with fonts, you need to install a font that supports the characters you wish to display, and tell prawn to use it.

prawn version 0.12.0 comes with one font which will at least display something:

pdf = Prawn::Document.new
pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
pdf.text "не ну ни фига sebe"
send_data pdf.render

If you want it prettier, you need to find and use another font, and modify the pdf.font line to use it.