Prawn:以PDF格式打印unicode字符串
我正在使用Prawn在Rails 3应用程序中生成PDF。
是否可以像在HTML视图中一样将Unicode字符串打印到PDF中?
例如,
在show.html.erb
导致字形show.html.erb
while
pdf.text raw "unicode_for_ཀ"
在show.pdf.prawn
中产生字符串"unicode_for_ཀ"
尝试在show.pdf.prawn
:
pdf.font "#{Prawn::BASEDIR}/data/fonts/TibMachUni-1.901b.ttf" do pdf.text raw "unicode_for_ཀ" end
和
pdf.font_families.update("TibMachUni" => {:normal => "#{Prawn::BASEDIR}/data/fonts/TibMachUni-1.901b.ttf" }) pdf.font("TibMachUni") do pdf.text raw "unicode_for_ཀ" end
这并没有解决问题。
你应该用
pdf.text raw "unicode_for_\u0F40"
代替
pdf.text raw "unicode_for_ཀ"
Ruby转义unicode字符的方法是\uXXXX
。
ཀ
escape是一个HTML / XML转义码,仅适用于第一个视图生成的HTML文件。