Matthias
Matthias

Reputation: 1953

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

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?

Upvotes: 2

Views: 1388

Answers (1)

Paul Fioravanti
Paul Fioravanti

Reputation: 16793

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.

Upvotes: 3

Related Questions