245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/ruby-fillform.rb', line 245
def fill_form_with(data={})
acroform_fields.each do |page, fields|
fields.each do |field|
number = page.to_s.split("_").last.to_i
go_to_page(number)
field_name_page = data[page][field.name]
value = field_name_page.fetch(:value) rescue nil
options = field_name_page.fetch(:options) rescue nil
if value.nil?
value = field_name_page.fetch(:value).to_s rescue nil
options = field_name_page.fetch(:options) rescue nil
end
options ||= {}
if value
value = value.to_s
x_offset = options[:x_offset] || 34
y_offset = options[:y_offset] || 38
if field.type == :text
fill_color options[:font_color] || field.font_color
font options[:font_face]
text_box value, :at => [field.x - x_offset, field.y - y_offset],
:align => options[:align] || field.align,
:width => options[:width] || field.width,
:height => options[:height] || field.height,
:valign => options[:valign] || :center,
:size => options[:font_size] || ((size = field.font_size) > 0.0 ? size : font_size),
:style => options[:font_style] || field.font_style
elsif field.type == :checkbox
is_yes = (v = value.downcase) == "yes" || v == "1" || v == "true"
formatted_text_box [{
text: is_yes ? Checkbox::YES : Checkbox::NO,
font: "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf",
size: options[:font_size] || field.font_size,
styles: options[:font_style] || [field.font_style]
}],
:at => [field.x - x_offset, field.y - y_offset],
:width => options[:width] || field.width,
:height => options[:height] || field.height
elsif field.type == :button
bounding_box([field.x + x_offset, field.y + y_offset], :width => field.width, :height => field.height) do
if value =~ /http/
image open(value), :position => options[:position] || :center,
:vposition => options[:vposition] || :center,
:fit => options[:fit] || [field.width, field.height]
else
image value, :position => options[:position] || :center,
:vposition => options[:vposition] || :center,
:fit => options[:fit] || [field.width, field.height]
end
end
end
end
end
end
references = References.new(state)
references.delete!
end
|