Search code examples
ruby-on-railsrubypdfprawn

Embedded Font Error for Rails Prawn Document


Just last week this was working fine and now my PDF documents are giving me this "Cannot extract the embedded font '1491bd-SourceHanSans-Normal'. Some Characters may not display correctly." error.

Been hunting for hours on this, and I looked at my recent commits and can't find any major changes that would cause this problem to arise suddenly.

Here's the basic code I am using to bug test.

def invoice_pdf
    require "prawn"
    # document set up
    Prawn::Document.generate("PDF.pdf", :page_size => "A4", :margin => [25], disposition: "inline") do |pdf|
        # set utf-8 japanese font
        pdf.font_families.update("SourceHan" => {
            :normal => ".fonts/SourceHan/SourceHanSans-Normal.ttf",
        })
        pdf.font "SourceHan" 
        pdf.font_size 10
        pdf.text 'ハロー ワルド。'
        send_data pdf.render, type: 'application/pdf', disposition: :inline
    end
end

It displays correctly when opened in Google Chrome. But using acrobat or other browsers (like Firefox that use the default system preview app) it gives me the error.

Thoughts?


Solution

  • There's a known issue with embedded fonts in the recently released ttfunk 1.6.0 gem.

    Have you updated that gem recently? If so, try downgrading it to 1.5.0 in your Gemfile and see if that helps.