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?
How to center table in prawn?
Asked Answered
I ran into the same error. Installing from master on Github fixed the issue.
# Gemfile
gem 'prawn', git: 'https://github.com/prawnpdf/prawn.git'
Probably good to mention setting a :ref in your Gemfile in case master becomes broken (then your production environment breaks). –
Westernize
Hope this helps
pdf.table tablename,
:border_width => 0,
:font_size => 11,
:position => :center
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
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
© 2022 - 2024 — McMap. All rights reserved.