I'm using Prawn
/ Prawnto_2
to generate PDFs for my Rails app. I'm trying to load a custom font, but keep getting the following error:
Prawn::Errors::UnknownFont in MyControllers#report
I placed the fonts in my assets/font
dir, restarted the server, but no luck.
My report.pdf.prawn
:
font_families.update(
"Garamond" => {
:normal => "#{Rails.root}/app/assets/fonts/Garamond/AGaramondPro-Regular.otf",
})
font("Garamond", :size => 10) do
text "Hello PDF"
end
It does work for Open Sans strangely, but have no luck with other fonts. What am I doing wrong here?
Prawn doesn't currently support OpenType Format (OTF) fonts (see this Github issue for details). If you're using an external font for your PDF, you're better off using a TrueType Font (TTF) file.