Class: Acrofill::Filler

Inherits:
Object
  • Object
show all
Defined in:
lib/acrofill/filler.rb

Overview

Public entry point, signature-compatible with PdfForms#fill_form:

Acrofill.new.fill_form(template, output, { 'Field' => 'value' }, flatten: true)

Note: PdfForms-specific options (data_format:, utf8_fields:, ...) are accepted and ignored — acrofill needs no FDF and is always UTF-aware.

Instance Method Summary collapse

Constructor Details

#initializeFiller

Accepts and ignores a pdftk path argument for drop-in compatibility.



12
# File 'lib/acrofill/filler.rb', line 12

def initialize(*); 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.



33
34
35
36
37
38
39
40
41
# File 'lib/acrofill/filler.rb', line 33

def apply(doc, destination, data, options)
  form = Form.new(doc)
  data.each do |name, value|
    form.fill(normalize(name), normalize(value))
  end
  form.flatten! if options[:flatten] || options['flatten']
  File.binwrite(destination, Writer.new(doc).render)
  destination
end

#field_names(template) ⇒ Object

Fully-qualified names of all fillable fields.



25
26
27
# File 'lib/acrofill/filler.rb', line 25

def field_names(template)
  fields(template).map(&:name)
end

#fields(template) ⇒ Object

Field metadata (name, type, current value, checkbox/radio states) without modifying the document.



20
21
22
# File 'lib/acrofill/filler.rb', line 20

def fields(template)
  Form.new(Document.new(template)).fields
end

#fill_form(template, destination, data = {}, options = {}) ⇒ Object



14
15
16
# File 'lib/acrofill/filler.rb', line 14

def fill_form(template, destination, data = {}, options = {})
  apply(Document.new(template), destination, data, options)
end