Question

I'm using ruby, prawn, and prawnto to dynamically generate pdf's containing text in other languages. I can't seem to get any text in languages with non-english characters to show up. It doesn't throw any errors...just shows a bunch of dashes instead of characters. Prawn brags on its homepage about UTF-8 support so I don't see why this is a problem. I'm using ruby 1.8.6 (engineyard).

Was it helpful?

Solution

For Unicode to work you need to load a TTF font that has the characters you require.

The default Helvetica font only supports ASCII (plus a few extras).

OTHER TIPS

Here is a example of prawn with unicode. Download the font from here. 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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top