zachhale (owner)

Revisions

gist: 23614 Download_button fork
public
Public Clone URL: git://gist.github.com/23614.git
Embed All Files: show embed
prawn cell height problem.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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