Embedded Font Error for Rails Prawn Document
Asked Answered
P

1

5

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?

Piggish answered 15/1, 2020 at 0:5 Comment(4)
my guess is that your other apps don't support Japanese font. Try adding Japanese-language/font support.Aircondition
Thanks for your comment. By "other apps" do you mean Adobe Acrobat? Firefox uses the Adobe Acrobat viewer for in browser PDF viewing by default, which is what I'm using. I have checked and Acrobat is in Japanese with Japanese language support on all user computers (including myself). If you mean my rails app. My config file specifies "config.i18n.default_locale = :'ja' " (Though I don't see how that would have an affect on embedded font files with the Prawn gem). Again, it works in Google Chrome. But doesn't outside of Chrome...So Strange.Piggish
Adobe seems to rely on the presence of fonts in your system. And SourceHanSans seems to have been included in Windows 10 "Creator's Update" (github.com/adobe-fonts/source-han-serif/issues/18). Most probably, the font is not yet installed in your system. You might need to install the font manually into your system(github.com/adobe-fonts/source-han-sans). ※I'm sorry I can only offer plausible explanations and not actual answers.Aircondition
Thanks again. I double checked and the PDF still displays incorrectly and shows the same error with the font confirmed installed. I find it strange that the error for the font includes "1491bd-" before the font name. I don't know much about PDF encoding, but my guess is that the Prawn gem (or the controller) is doing something strange with the encoding of the font if it's showing up that way.Piggish
T
6

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.

Tjaden answered 15/1, 2020 at 4:22 Comment(3)
You are a small god, thank you. This solved it. In case anyone is interested in following the issue: github.com/prawnpdf/ttfunk/issues/73Piggish
We've been having this issue for a year. so glad I just found this. Thank you!!!!Gaucho
I have been losing my mind this afternoon. Thank you!Leeward

© 2022 - 2024 — McMap. All rights reserved.