Class: Acrofill::Filler
- Inherits:
-
Object
- Object
- Acrofill::Filler
- Defined in:
- lib/acrofill/filler.rb
Overview
Instance Method Summary collapse
-
#apply(doc, destination, data, options) ⇒ Object
Shared fill pipeline, also driven by Template with a restored document.
-
#field_names(template) ⇒ Object
Fully-qualified names of all fillable fields.
-
#fields(template) ⇒ Object
Field metadata (name, type, current value, checkbox/radio states) without modifying the document.
- #fill_form(template, destination, data = {}, options = {}) ⇒ Object
-
#initialize(_pdftk_path = nil, options = {}, **kwargs) ⇒ Filler
constructor
Accepts and ignores a pdftk path argument for drop-in compatibility.
Constructor Details
#initialize(_pdftk_path = nil, options = {}, **kwargs) ⇒ Filler
Accepts and ignores a pdftk path argument for drop-in compatibility. Options given here are defaults for every #fill_form call, the way PdfForms.new(path, flatten: true) behaves — accepting them and then ignoring them would silently ship unflattened documents.
15 16 17 |
# File 'lib/acrofill/filler.rb', line 15 def initialize(_pdftk_path = nil, = {}, **kwargs) @options = (.is_a?(Hash) ? : {}).merge(kwargs) end |
Instance Method Details
#apply(doc, destination, data, options) ⇒ Object
Shared fill pipeline, also driven by Template with a restored document. Values are normalized to valid UTF-8 up front so that a mis-encoded input degrades (replacement character) instead of leaking a raw Encoding error from deep inside the appearance code.
38 39 40 41 42 43 44 45 46 |
# File 'lib/acrofill/filler.rb', line 38 def apply(doc, destination, data, ) form = Form.new(doc) (data || {}).each do |name, value| form.fill(normalize(name), normalize(value)) end form.flatten! if flatten?() write(destination, Writer.new(doc).render) destination end |
#field_names(template) ⇒ Object
Fully-qualified names of all fillable fields.
30 31 32 |
# File 'lib/acrofill/filler.rb', line 30 def field_names(template) fields(template).map(&:name) end |