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