Rails: Why does Prawn give me an Unkown Font Error when loading a custom font for my PDF?

1.3k views Asked by At

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?

1

There are 1 answers

0
Paul Fioravanti On BEST ANSWER

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.