prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 98 forks source link

Using prawn.icon #124

Open alliedarmour opened 4 years ago

alliedarmour commented 4 years ago

Hey, first thanks for the great gem! I recently tried to use the prawn-icongem to include Font Awesome icons in my PDF document.

The issue is the following: I need the icons for my table, so I'm using the table_icon helper:

prawn_document(page_layout: :landscape, page_size: "A6", filename: "Bestellungen_#{I18n.l(Date.today)}") do |pdf|
    # pdf.font_families.update(
    #     "Font Awesome" => { :normal => Rails.root.join("app", "assets", "fonts", "fa-solid-900.ttf") }
    # )

    @orders.each do |order|
        data = [ 
            ["Salat", "Suppe", "Dessert"],
            [pdf.table_icon('fas-birthday-cake')]
        ]
        pdf.font("Helvetica", size: 20, style: :bold) do 
            pdf.float { pdf.text(order.user.name, align: :left) }
            pdf.text(l(order.day), align: :right)
        end
        pdf.move_down 10
        pdf.table(data)
    end
end

Without changing the font for the whole document to Font Awesome with pdf.font "Font Awesome", I keep getting the following error:

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

But unfortunately it neither works when I just change the cell font type like this:

   cell_1 = pdf.make_cell(pdf.table_icon('fas-birthday-cake'))
   cell_1.font = "Font Awesome"

Is there anything I can do to use the gem with prawn-rails? Or might it be a problem with prawn-table?

jessedoyle commented 4 years ago

Hi Guys! I'm the author of prawn-icon and I've done a bit of research here.

It looks like https://github.com/prawnpdf/prawn-table/pull/60 was merged in years ago, but a release was never made on Rubygems. This PR should resolve the issue that @alliedarmour is running into.

Can someone please cut a new release on Rubygems?

alliedarmour commented 4 years ago

I can confirm that it's working with that PR without problems. A new release would be awesome!