Question

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
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top