Print symbols like ≥ → ∏ and similars

25 views
Skip to first unread message

Juan Calderón

unread,
Feb 26, 2019, 2:13:04 PM2/26/19
to Prawn
Hello,

How to print characters like  ≥ → ∏ ?

Always it prints something like ≥ → ∕

Thank you.



Alexander Mankuta

unread,
Feb 26, 2019, 2:27:27 PM2/26/19
to Prawn
Hi Juan,

Looks like you have wrong encoding on your string.

Could you please provide a sample script that demonstrates your issue?

--
Regards,
Alex

Juan Calderón

unread,
Feb 26, 2019, 5:54:35 PM2/26/19
to Prawn
The code:

format.pdf do
    pdf = Prawn::Document.new
    pdf.text "Hello World"
    pdf.text "ƒ ≥ → ∏".force_encoding("Windows-1252")
    pdf.render_file "public/#{filename}"
    send_data pdf.render, filename: filename, type: 'application/pdf', disposition: "inline"

The result:
    Hello World
    Æ’ ≥ → ∕

Without .force_encoding("Windows-1252"), send:

  Your document includes text that's not compatible with the Windows-1252 character set. If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts.

Alexander Mankuta

unread,
Feb 27, 2019, 3:34:53 AM2/27/19
to Prawn
You have to use an external font that provides characters you need. The built-in ones do not have them and that's the reason you're getting the error without force_encoding.

Here's Windows-1252 charset. As you can see, it doesn't provide a single character you want to display.

--
Regards,
Alex

Juan Calderón

unread,
Feb 27, 2019, 1:13:41 PM2/27/19
to Prawn
Thank you for your answer.

The solution was this line:

pdf.font "/Library/Fonts/Arial Unicode.ttf"

Thanks
Reply all
Reply to author
Forward
0 new messages