Setting the width of the cell / column on the shrimp table

I am making a small script with ruby ​​that creates a weekly schedule PDF file using Prawn as a PDF library and I struggle with table layout. I would like to set a static width for all columns of the table so that the width does not depend on the contents of the cells.

I read the documentation (a lot of room for improvement there) from the Prawn and googled project site for several hours, but I lost how to set the width for columns or cells in the table, or how the style of columns / cells in any way. I get a PDF file that has a grid layout, although the cells just vary a lot in size, which doesn't look so neat.

This did not work:

Prawn::Document.generate(@filename, :page_size => 'A4', :page_layout => :landscape) do
  table(course_matrix, :headers => HEADERS, :border_style => :grid, :row_colors => ['dddddd', 'eeeeee'], :column_widths => 50)
end

Here is the current version of my method for creating a PDF, but it does not style the cells:

def produce_pdf
  course_matrix = DataParser.new.parse_for_pdf

  Prawn::Document.generate(@filename, :page_size => 'A4', :page_layout => :landscape) do
    table(course_matrix, :headers => HEADERS, :border_style => :grid, :row_colors => ['dddddd', 'eeeeee']) do |table|
      table.cells.style { |cell| cell.width = 50 }
    end
  end
end
+5
2

- :

pdf = Prawn::Document.new(
  :page_size => 'A4',
  :page_layout => :landscape,
  :margin => [5.mm])
  ....
  .... 
  pdf.table(tbl_data) do
    row(0).style(:background_color => 'dddddd', :size => 9, :align => :center, :font_style => :bold)
    column(0).style(:background_color => 'dddddd', :size => 9, :padding_top => 20.mm, :font_style => :bold)
    row(1).column(1..7).style(:size => 8, :padding => 3)
    cells[0,0].background_color = 'ffffff'
    row(0).height = 8.mm
    row(1..3).height = 45.mm
    column(0).width = 28.mm
    column(1..7).width = 35.mm
    row(1..3).column(6..7).borders = [:left, :right]
    row(3).column(6..7).borders = [:left, :right, :bottom]
  ....
 pdf.render()

.

+11

, - :

REPORT_FIELDS = %w[DESCRIPTION PRICE DATE NOTE].freeze
A4_SIZE = 200.freeze

data = []
data << REPORT_FIELDS
... things happen ...
table(data, column_widths: (A4_SIZE/REPORT_FIELDS.size).mm))

, .

0

All Articles