How to center table in prawn?
Asked Answered
M

3

6

I have created a table in prawn and wanted to pass the :position option by whih is also documented in the manual but it throws off an Method_missing error. It seems like this parameter doesnt exist anymore. How can I center a table in prawn?

Moores answered 8/3, 2012 at 14:6 Comment(0)
S
5

I ran into the same error. Installing from master on Github fixed the issue.

# Gemfile
gem 'prawn', git: 'https://github.com/prawnpdf/prawn.git'

Issue thread on Github

Shadowgraph answered 4/10, 2012 at 8:40 Comment(1)
Probably good to mention setting a :ref in your Gemfile in case master becomes broken (then your production environment breaks).Westernize
L
4

Hope this helps

pdf.table tablename,
    :border_width => 0,
    :font_size => 11,
    :position => :center
Loner answered 7/5, 2012 at 9:3 Comment(3)
Like I said when I try to use that option I get an undefined method error: Error: /usr/local/lib/ruby/gems/1.9.1/gems/prawn-0.12.0/lib/prawn/table.rb:125:in block in initialize': undefined method position=' for #<Prawn::Table:0x000000056768f8> (NoMethodError)Moores
try installing gem 'prawn-layout' or try this if the above does not work gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git"Loner
If we are suppose to pointing to that git, how if someday that git was deleted? Is there aren't any other way to solve that?Coopt
T
0

whether the PDF generation is from a declared class or within the controller you need to add the following line to your Gemfile

gem 'prawn-table', '~> 0.2.1'

At the time of writing that is the gem version, this will give you access to the table methods such as position

I used it in this example and it worked

def table_items(chart_data, doc)
  table = Prawn::Table.new(table_rows(chart_data), doc, {:header => true})
  table.row(0).font_style = :bold
  table.position = :center
  table.draw
end
Thrombosis answered 24/11, 2014 at 13:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.