Skip to content

Instantly share code, notes, and snippets.

@lappi-lynx
Last active January 29, 2016 12:15
Show Gist options
  • Save lappi-lynx/16fe4a4033e3997b0dc4 to your computer and use it in GitHub Desktop.
Save lappi-lynx/16fe4a4033e3997b0dc4 to your computer and use it in GitHub Desktop.
Multi-column PDF generating with Prawn in ruby
# Not breaking the page but continue on the next column
# Example of 2 columns table with some styling
def render_left_products_list
column_box([-5, cursor], columns: 2, height: cursor, position: :left, width: bounds.width, spacer: 40) do
@categories.each do |category|
move_down 6
table line_item_rows(category), position: :left, cell_style: { size: 7, text_color: "000000", borders: [:bottom], border_lines: [:dotted], padding: [2, 0, 4, 0] } do
column(1).style align: :right
style(row(0), text_color: 'FF0000')
align = { 0 => :left, 1 => :right}
self.width = 285
self.header = true
column(1).font_style = :bold
row(0).size = 8
row(0).font_style = :bold
row(0).borders = []
end
end
end
end
def line_item_rows(category)
[[category.name, '']] +
category.products.map do |product|
[product.name, "#{format('%.2f', product.price)} USD"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment