I recently used Prawn (version 2.0.2 with prawn-table
version 0.2.2) to generate a PDF in Japanese, and unfortunately didn't have any luck with any of the TTF fonts posted in the accepted answer (the accepted answer was still of great help in knowing that Japanese text can't be rendered with Prawn's built-in fonts, though!).
I did, however, have luck using the TTF files from IPA fonts with Prawn, specifically the "4 fonts package" they have listed on the page which contains the IPA Mincho and IPA Gothic fonts. I used the IPAPMincho font (ipamp.ttf
) for "normal" font, and IPAPGothic (ipagp.ttf
) for "bold"; they are different fonts, but one worked for me as the "bold version" of the other.
In my Prawn configuration, I used default fonts where I could (say, for English documents), but the TTF files for Japanese, which were configured in on-the-fly. This lead to code that looked similar to the following:
Prawn::Document.generate("MyJapaneseDocument.pdf") do |pdf|
# assume `font_name` here is something like "IPA",
# ie not a font that is shipped with the Prawn gem
unless Prawn::Font::AFM::BUILT_INS.include?(font_name)
pdf.font_families.update(
font_name => {
normal: "path/to/ipamp.ttf",
bold: "path/to/ipagp.ttf"
}
)
end
pdf.font font_name
end