Class: Mypdf

Inherits:
FPDF
  • Object
show all
Defined in:
lib/mypdf.rb

Instance Method Summary collapse

Instance Method Details

#BasicTable(header, data) ⇒ Object

Simple table



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/mypdf.rb', line 129

def BasicTable(header, data)
 # Header
 header.each do |col|
 Cell(40, 7, col, 1)
 end
 Ln()
 # Data
 data.each do |row| 
  row.each {|col| Cell(40, 6, col, 1)}
  Ln()
 end
end

#FancyTable(header, data, wh, wd, fillcolor, textcolor, drawcolor, linewidth, font, fillcolorRestart, textcolorRestart, fontRestart) ⇒ Object

Colored table



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/mypdf.rb', line 174

def FancyTable(header, data, wh, wd, fillcolor, textcolor, drawcolor, linewidth, font, fillcolorRestart, textcolorRestart, fontRestart)
 # Colors, line width and bold font
 SetFillColor(fillcolor[0], fillcolor[1], fillcolor[2])
 SetTextColor(textcolor)
 SetDrawColor(drawcolor[0], drawcolor[1], drawcolor[2])
 SetLineWidth(linewidth)
 SetFont(font[0].to_s,font[1].to_s,font[2])
 # Column widths
 j=0
 0.upto(header.length - 1) do |i|
  Cell(wh[i,j], wh[i,j+1], header[i], wh[i,j+2], wh[i,j+3], wh[i,j+4].to_s,1)
 end
 Ln()
 # Color and font restoration
 SetFillColor(fillcolorRestart[0], fillcolorRestart[1], fillcolorRestart[2])
 SetTextColor(textcolorRestart)
 SetFont(fontRestart[0].to_s,fontRestart[1].to_s,fontRestart[2])
 # Data
 fill = 0 
 # Data
 i=0
 k=0
 longitud = data.length
 data.each do |row| 
  row.each do |col| 
   Cell(wd[i,j], wd[i,j+1], col.to_s, wd[i,j+2].to_s, wd[i,j+3], wd[i,j+4].to_s,fill)
   i=i+1
  end
  if k!=longitud
   Ln()
  end
  k=k+1
  fill = (fill == 0 ? 1 : 0)
 end
 # Closure line
 sum = 0
 for i in 0..header.length-1
  sum += wh[i,0]
 end
 Cell(sum, 0, '', 'T')
end


110
111
112
113
114
115
116
117
118
# File 'lib/mypdf.rb', line 110

def Footer()
 # font
 SetFont(@fontf[0].to_s,@fontf[1].to_s,@fontf[2])
 # Posicion: a -y cms del final
 SetY(@y)
 # Numero de pagina
 nro = PageNo()
 Cell(@pagef[0],@pagef[1],@pagef[2].to_s+nro.to_s+'/{nb}',@pagef[3],@pagef[4],@pagef[5].to_s)
end

#FooterPage(font, y, page) ⇒ Object

Pie de pagina. Metodo agregado por [email protected]



104
105
106
107
108
# File 'lib/mypdf.rb', line 104

def FooterPage(font,y,page)
 @fontf = font
 @y = y
 @pagef = page
end

#HeaderObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mypdf.rb', line 84

def Header()
 #Font
 SetFont(@font[0].to_s,@font[1].to_s,@font[2])
 # Logos
 Image(@image1[0].to_s,@image1[1],@image1[2],@image1[3],@image1[4])
 Image(@image2[0].to_s,@image2[1],@image2[2],@image2[3],@image2[4])
 # titulos 4 lineas de encabezado
 SetXY(@xy1[0],@xy1[1])
 Cell(@title1[0],@title1[1],@title1[2].to_s,@title1[3],@title1[4],@title1[5].to_s)
 SetXY(@xy2[0],@xy2[1])
 Cell(@title2[0],@title2[1],@title2[2].to_s,@title2[3],@title2[4],@title2[5].to_s)
 SetXY(@xy3[0],@xy3[1])
 Cell(@title3[0],@title3[1],@title3[2].to_s,@title3[3],@title3[4],@title3[5].to_s)
 SetXY(@xy4[0],@xy4[1])
 Cell(@title4[0],@title4[1],@title4[2].to_s,@title4[3],@title4[4],@title4[5].to_s)
 # Salto de lineas
 Ln(@lines)
end

#HeaderPage(font, image1, image2, xy1, title1, xy2, title2, xy3, title3, xy4, title4, lines) ⇒ Object

Encabezado de Pagina. Metodo agregado por [email protected]



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mypdf.rb', line 69

def HeaderPage(font,image1,image2,xy1,title1,xy2,title2,xy3,title3,xy4,title4,lines)
 @font = font
 @image1 = image1
 @image2 = image2
 @xy1 = xy1
 @xy2 = xy2
 @xy3 = xy3
 @xy4 = xy4
 @title1 = title1
 @title2 = title2
 @title3 = title3
 @title4 = title4
 @lines = lines
end

#ImprovedTable(header, data, wh, wd) ⇒ Object

Better table



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/mypdf.rb', line 143

def ImprovedTable(header, data, wh, wd)
 # Column widths
 j=0
 0.upto(header.length - 1) do |i|
  Cell(wh[i,j], wh[i,j+1], header[i], wh[i,j+2], wh[i,j+3], wh[i,j+4].to_s)
 end
 Ln()
 # Data
 i=0
 k=0
 longitud = data.length
 data.each do |row| 
  row.each do |col| 
   #col.to_s.reverse.gsub(/\d{3}(?=\d)/, '\&,').reverse
   Cell(wd[i,j], wd[i,j+1], col.to_s, wd[i,j+2].to_s, wd[i,j+3], wd[i,j+4].to_s)
   i=i+1
  end
  if k!=longitud
   Ln()
  end
  k=k+1
 end
 # Closure line
 sum = 0
 for i in 0..header.length-1
  sum += wh[i,0]
 end
 Cell(sum, 0, '', 'T')
end

#LoadData(file) ⇒ Object

Load data



121
122
123
124
125
126
# File 'lib/mypdf.rb', line 121

def LoadData(file)
 data = Array.new
 # Read file lines
 IO.foreach(file) {|line| data.push(line.chop.split(';'))}
 return data
end