Class: FillPdf::Fill
- Inherits:
-
Object
- Object
- FillPdf::Fill
- Defined in:
- lib/fill_pdf/methods.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
-
#dirname ⇒ Object
Returns the value of attribute dirname.
-
#pdftk ⇒ Object
Returns the value of attribute pdftk.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#export ⇒ Object
This method populate attributes with data based on template fields.
-
#initialize(template, dictionary = {}) ⇒ Fill
constructor
Template is path of a pdf file.
-
#populate ⇒ Object
Populate all pdf fields with values.
-
#template_field_names ⇒ Object
Return list of template fields in array.
Constructor Details
#initialize(template, dictionary = {}) ⇒ Fill
Template is path of a pdf file
7 8 9 10 11 12 13 |
# File 'lib/fill_pdf/methods.rb', line 7 def initialize(template, dictionary={}) @attributes = {} @template = template @dictionary = dictionary @dirname = Rails.application.config.fill_pdf.output_path @pdftk = PdfForms.new(Rails.application.config.fill_pdf.pdftk_path) end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/fill_pdf/methods.rb', line 3 def attributes @attributes end |
#dictionary ⇒ Object
Returns the value of attribute dictionary.
3 4 5 |
# File 'lib/fill_pdf/methods.rb', line 3 def dictionary @dictionary end |
#dirname ⇒ Object
Returns the value of attribute dirname.
3 4 5 |
# File 'lib/fill_pdf/methods.rb', line 3 def dirname @dirname end |
#pdftk ⇒ Object
Returns the value of attribute pdftk.
3 4 5 |
# File 'lib/fill_pdf/methods.rb', line 3 def pdftk @pdftk end |
#template ⇒ Object
Returns the value of attribute template.
3 4 5 |
# File 'lib/fill_pdf/methods.rb', line 3 def template @template end |
Instance Method Details
#export ⇒ Object
This method populate attributes with data based on template fields.
Generate document path.
Create new document and return path of this document.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fill_pdf/methods.rb', line 37 def export # Create directory used for store documents Dir.mkdir(@dirname) unless File.directory?(@dirname) #call method populate to set field with value. populate # Generate Path of document document = Rails.root.join(dirname, "#{SecureRandom.uuid}.pdf") # Generate document pdftk.fill_form template, document, attributes, :flatten => true # Return path of document document rescue Exception => exception logger exception end |
#populate ⇒ Object
Populate all pdf fields with values.
23 24 25 26 27 28 29 |
# File 'lib/fill_pdf/methods.rb', line 23 def populate @attributes = {} template_field_names.each do |field| set(field, value(field).to_s) end @attributes end |
#template_field_names ⇒ Object
Return list of template fields in array
17 18 19 |
# File 'lib/fill_pdf/methods.rb', line 17 def template_field_names pdftk.get_field_names template end |