Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the font size in a prawn table?

How do I set the font size in a PDF table using the prawn gem?

When I call prawn like the following:

pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
pdf.table data, 
    :header => true,
    :column_widths => widths,
    :font_size => 7,
    :row_colors => ["EEEEEE", "FFFFFF"]

I get an NoMethodError

undefined method `font_size=' for #<Prawn::Table:0x6ce37ea4>

When I remove the ":font_size => 7", it renders but I get an undesirable font size.

I am using prawn 0.12.0, ruby 1.9.3p194, and Rails 3.1.9.

like image 379
Marlin Pierce Avatar asked Jul 17 '13 15:07

Marlin Pierce


2 Answers

You have to apply the size property to the cell text directly. Here is how to do this:

pdf.table data, 
  :header => true,
  :column_widths => widths,
  :cell_style => { size: 7 },
  :row_colors => ["EEEEEE", "FFFFFF"]

Source: http://prawn.majesticseacreature.com/manual.pdf

like image 189
siekfried Avatar answered Oct 13 '22 14:10

siekfried


:font_size => 7 not works.

The correct way is :size => 7

    pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
    pdf.table data, 
    :header => true,
    :column_widths => widths,
    :size => 7,
    :row_colors => ["EEEEEE", "FFFFFF"]
like image 33
lstefani Avatar answered Oct 13 '22 16:10

lstefani