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
32
33
34
35
36
37
38
39
|
# File 'lib/generators/templates/app/models/pdf_report.rb', line 3
def to_pdf(model, mode_scope)
columns = model.attribute_names
data = [columns]
mode_scope.each{ |modelobj|
data << (columns.map{ |c| modelobj[c].to_s }).to_a
}
table data, :header => true, :cell_style => { :padding => 5 } do
i = 0
for col in columns
align = case model.columns_hash[col].type
when "integer" then
'right'
when "string", "text" then
'left'
else
'center'
end
style(columns(i)){ |c| c.align = align.to_sym }
i += 1
end
end
font_size 10
number_pages Time.now.strftime('%d/%m/%Y - %H:%M') + ' - <page>/<total>', :at => [0, -5], :align => :center
repeat(:all) do
bounding_box([0,0], :width => 540, :height => 2) do
stroke_horizontal_rule
end
end
render
end
|