Skip to content

Instantly share code, notes, and snippets.

@zachhale
Created November 10, 2008 20:13
Show Gist options
  • Save zachhale/23614 to your computer and use it in GitHub Desktop.
Save zachhale/23614 to your computer and use it in GitHub Desktop.
# cell widths
cell_widths = [160,60]
# example data for rows_to_pdf
rows_to_pdf = [
['Row Name','200',300','400'],
['Row Name','200',300','400'],
['Row Name','200',300','400'],
['Row Name','200',300','400'],
['Row Name','200',300','400']
]
# build the row of cells
pdf.font 'Helvetica'
pdf.text_options.update(:size => 8)
rows_to_pdf.each do |cells|
new_cells = []
cells.each_with_index do |old_cell,cell_index|
new_cells << Prawn::Graphics::Cell.new(
:border_width => 0.5, :horizontal_padding => 1, :vertical_padding => 0,
:width => (cell_index>0 ? cell_widths[1] : cell_widths[0]),
:align => (cell_index>0 ? :right : :left),
:text => old_cell, :borders => [:bottom], :document => pdf)
end
cellblock = Prawn::Graphics::CellBlock.new(pdf)
new_cells.each do |new_cell|
cellblock << new_cell
end
pdf.move_down(1)
cellblock.draw
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment