tyb*_*103 9 pdf ruby-on-rails utf-8 prawn prawnto
我正在使用ruby,prawn和prawnto动态生成包含其他语言文本的pdf.我似乎无法使用非英文字符的语言显示任何文本.它不会抛出任何错误...只显示一堆破折号而不是字符.Prawn在其主页上讨论UTF-8支持,所以我不明白为什么这是一个问题.我正在使用红宝石1.8.6(发动机厂).
Jam*_*aly 12
要使Unicode工作,您需要加载具有所需字符的TTF字体.
默认的Helvetica字体仅支持ASCII(加上一些附加功能).
这是一个带unicode的虾的例子.从这里下载字体.http://www.siyabas.lk/files/iskpota.ttf
#!/bin/env ruby
# encoding: utf-8
require 'prawn'
pdf = Prawn::Document.new
pdf.font_families.update("Iskoola Potha Unicode"=>{:normal =>"fonts/iskpota.ttf"})
pdf.font "Iskoola Potha Unicode"
pdf.text "???????? ????? …"
pdf.move_down 10
pdf.text "
?????? ?????? ??? ????? ??? ?????? ???? ????. 
??? ??? ?? ????????? ???????? ??? ???? ??? ? ??? ???? ????? ????? ??? 
?? ?????? ???? ?? ???. ???????? ?????? ???? ?????? ??? ???? ???????? ??? 
???? ?????? ???? ?????? ??? ????? ????? ???????. ????????? ??? ??????? 
?????? ????? ??????? ???? ???? ????? ??????? ?????? ???. ???? ??? ??????? ?? 
????????? ????? ???? ??? ????? ??????, ????? ????? ?? ????????? ????? ???? ??? 
???? ???????? ????????. ??? ??? ???? ????? ?????? ?? ??????. ???? ????? 
???? ????? 2?? ??? ???? ????? ?????? ????? ?? ????? ??? ????? ??? 
????????? ????? ???. ????? ???? ????? ????????? ???? ????????? 
(?????????? ?????? ??????) ????? ???? ????? ?????? ??? ??????? ?? ???? ??; 
??????? ???? ????? ???? ????? ?? ?????? ?????? ???? ???? ???????? ???? 
??????? ???? ???????? ?????? ????? ???? ?? ???????? ???? ?? ??."
pdf.stroke_horizontal_rule
pdf.render_file "sinhala.pdf"
Run Code Online (Sandbox Code Playgroud)