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).
Asked
Active
Viewed 8,275 times
11
-
You'll need to give us some more detail or an example. Which characters are you trying to render, in what font? Do they just not show up or do you have an error or exception? Is this Ruby 1.8 or 1.9? If you take the UTF-8 example on the Prawn homepage, paste it in a text file and run it standalone with your Ruby setup, does it work? – Stéphan Kochen Jan 20 '10 at 20:52
-
I edited the question to answer most of that. – tybro0103 Jan 20 '10 at 21:22
-
Do you use Ruby or Rails? – Katarzyna Apr 27 '15 at 01:36
2 Answers
12
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).

James Healy
- 14,557
- 4
- 33
- 43
-
5I suggest you try the DejaVu font family, which supports a fairly large chunk of the Unicode standard. You can find it at: http://dejavu-fonts.org/ (The Prawn gem includes DejaVu Sans, specifically in prawn-core/data/fonts/DejaVuSans.ttf) – Stéphan Kochen Jan 21 '10 at 18:12
-
The DejaVu had a lot of the characters I needed...didn't have Chinese though. I did find a font called "Arial Unicode MS" already on my mac in the fontbook program that seems to do it all. Thanks! – tybro0103 Jan 21 '10 at 19:34
-
The [manual](http://prawnpdf.org/manual.pdf) suggests (section *text/utf8*) `font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") { text "ὕαλον φαγεῖν δύναμαι" }` to use the *DejaVuSans* font. – fiedl Jul 18 '14 at 14:58
-
Thanks. This helped me find font that supported the logical symbol 'therefore'. Here is a list of fonts that support that. https://www.fileformat.info/info/unicode/char/2234/fontsupport.htm – Harry Fairbanks Nov 23 '18 at 07:08
6
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"

Gihan De Silva
- 458
- 8
- 17