Reputation: 33
I'm using Prawn to generate PDFs in a Rails 3 app.
Is it possible to print a Unicode string into a PDF like in a HTML view?
For example,
<%= raw "unicode_for_ཀ" %>
in show.html.erb
results in the glyph ཀ while
pdf.text raw "unicode_for_ཀ"
in show.pdf.prawn
results in the string "unicode_for_ཀ"
Tried in show.pdf.prawn
:
pdf.font "#{Prawn::BASEDIR}/data/fonts/TibMachUni-1.901b.ttf" do
pdf.text raw "unicode_for_ཀ"
end
and
pdf.font_families.update("TibMachUni" => {:normal => "#{Prawn::BASEDIR}/data/fonts/TibMachUni-1.901b.ttf" })
pdf.font("TibMachUni") do
pdf.text raw "unicode_for_ཀ"
end
This did not solve the problem.
Upvotes: 3
Views: 3752
Reputation: 10205
You should use
pdf.text raw "unicode_for_\u0F40"
instead of
pdf.text raw "unicode_for_ཀ"
The Ruby way to escape unicode characters is \uXXXX
.
The ཀ
escape is an HTML/XML escape code and works only because the first view generated an HTML file.
Upvotes: 8