Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:14:29+00:00 2026-06-05T22:14:29+00:00

I’m creating generator of pdf documents in Ruby on Rails with Prawn gem and

  • 0

I’m creating generator of pdf documents in Ruby on Rails with Prawn gem and I came up with issue that when I have Chinese, Japanese and Cyrillic chars they are displayed incorrectly.
I googled out that it’s because “when I’m generating font I need to specify, what font should pdf text be rendered with”.

Now this isn’t the issue, but the fact that my documents will include all different possible chars that gTLD supports.

Question 1:

Do you know any font for generating pdf documents that will include as many as possible chars (Asian, Europe, Symbols, …)? Ideally all chars that gTLD supports.

I know that Prawn by default includes gkai00mp.ttf but its focused on Chinese chars and I’m looking for permissibility to include them all (Like PokeMon, got to catch them all; I know I’m asking for too much but still…)

Another issue is when client opens this document:

Question 2

Is pdf generated by Prawn including my font in pdf file, so when other computers open it, the font will be present? Is this by default standard? Or I need to ensure/force this functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:14:31+00:00Added an answer on June 5, 2026 at 10:14 pm

    Ok, going to answer it by myself. On SuperUser I asked similar question (focusing on answers in more theoretical way), and the main conclusion was answer that:

    There is no single font that supports the whole of Unicode.

    but fortunately pdf supports fall-back fonts, and prawn gem too.

    here is my solution:

    1/ set your fall-back fonts

      kai = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
      action_man_path = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
      dejavu = "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
    
      font_families.update("dejavu" => {
        :normal      => dejavu,
        :italic      => dejavu,
        :bold        => dejavu,
        :bold_italic => dejavu
      })
    
      #Times is defined in prawn
      font_families.update("times" => {
        :normal => "Times-Roman",
        :italic      => "Times-Italic",
        :bold        => "Times-Bold",
        :bold_italic => "Times-BoldItalic"
      })
    
      font_families.update("action_man" => {
        :normal      => { :file => action_man_path, :font => "ActionMan" },
        :italic      => { :file => action_man_path, :font => "ActionMan-Italic" },
        :bold        => { :file => action_man_path, :font => "ActionMan-Bold" },
        :bold_italic => { :file => action_man_path, :font => "ActionMan-BoldItalic" }
      })
    
      font_families.update(
          "kai" => {
            :normal => { :file => kai, :font => "Kai" },
            :bold   => kai,
            :italic => kai,
            :bold_italic => kai
           }
        )
    

    and

    def fallback_fonts
      ["dejavu", "times", 'kai', 'action_man']
    end
    

    2/ call

     font("Helvetica", size: 14) do  #keyword "Helvetica" is specified in Prawn by default
       text "址 foo", :fallback_fonts => fallback_fonts 
     end
    

    Now, here I’m just using fonts that are included in Prawn by default, but this way you can add several fonts with different charsets and just specify them as fall-back

    For example you can put your fonts somewhere in your Rails root and just include them from there

    note in “Kai” font, I’m specifying same font for normal, italic, bold, bold_italic without styling. I’m doing this on purpose. From what I was experiencing gkai00mp font don’t have bold chars or italic chars. So when italic/bold char get rendered it will be printed in normal style (which is better than not to render at all).

    If I don’t specify bold/italic font for font (exaple “Kai”)..

      font_families.update(
          "kai" => {
            :normal => { :file => kai, :font => "Kai" }
            }
        )
    

    .. and you try to render styled char that will fall-back to kai…

     text "<b>址 foo</b>", :fallback_fonts => fallback_fonts, :inline_format=>true 
    

    …I’ll get

    Prawn::Errors::UnknownFont in Foo
    
      is not a known font. 
    

    note 2: if you want to put non-ascii chars to ruby file you need to put encoding at top of the file

    # coding: utf-8
    
    class Foo
    ...
    end
    

    this however works form ruby 1.9. Ruby 1.8.x source can handle ASCII only (more on that in ruby 1.9 walkthrough by P.C.
    but in Rails you should use I18n (internationalization)

    note 3

    Prawn has really great documentation, just git clone prawn from github and check ./manuals

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.