Class: PdfForm
- Inherits:
-
Object
- Object
- PdfForm
- Defined in:
- app/pdf_forms/pdf_form.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ PdfForm
constructor
A new instance of PdfForm.
- #save_as(path:, read_only: true, signed_by: '') ⇒ Object
- #to_file(read_only: true, signed_by: '') ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ PdfForm
Returns a new instance of PdfForm.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/pdf_forms/pdf_form.rb', line 4 def initialize(data = {}) @data = data @pdf = FillablePDF.new(self.class.template_path) @pdf.set_fields( self.class.flattened_fields( data, self.class.boxes_by_field_name, self.class.field_name_prefixes ) ) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
2 3 4 |
# File 'app/pdf_forms/pdf_form.rb', line 2 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
2 3 4 |
# File 'app/pdf_forms/pdf_form.rb', line 2 def path @path end |
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
2 3 4 |
# File 'app/pdf_forms/pdf_form.rb', line 2 def pdf @pdf end |
Instance Method Details
#save_as(path:, read_only: true, signed_by: '') ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/pdf_forms/pdf_form.rb', line 17 def save_as(path:, read_only: true, signed_by: '') flatten = signed_by.present? || read_only @pdf.save_as(path, flatten: flatten) @path = path sign(content: signed_by) if signed_by.present? @path end |
#to_file(read_only: true, signed_by: '') ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/pdf_forms/pdf_form.rb', line 26 def to_file(read_only: true, signed_by: '') tempfile = Tempfile.new(["#{SecureRandom.uuid}_#{Time.now.to_i}", '.pdf']) save_as(path: tempfile.path, read_only: read_only, signed_by: signed_by) @path = tempfile.path tempfile.rewind tempfile end |