Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment