Class: PdftkForms::Fdf

Inherits:
Object
  • Object
show all
Defined in:
lib/pdftk_forms/fdf.rb

Overview

Map keys and values to Adobe’s FDF format.

Straight port of Perl’s PDF::FDF::Simple by Steffen Schwigon. Parsing FDF files is not supported (yet).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, options = {}) ⇒ Fdf

Returns a new instance of Fdf.



11
12
13
14
15
16
17
18
# File 'lib/pdftk_forms/fdf.rb', line 11

def initialize(data = {}, options = {})
  @data = data
  @options = {
    :file => nil,
    :ufile => nil,
    :id => nil
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/pdftk_forms/fdf.rb', line 9

def options
  @options
end

Instance Method Details

#save_to(path) ⇒ Object

write fdf content to path



39
40
41
# File 'lib/pdftk_forms/fdf.rb', line 39

def save_to(path)
  (File.open(path, 'w') << to_fdf).close
end

#to_fdfObject

generate FDF content



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdftk_forms/fdf.rb', line 21

def to_fdf
  fdf = header
  
  @data.each do |key, value|
    if Hash === value
      value.each do |sub_key, sub_value|
        fdf << field("#{key}_#{sub_key}", sub_value)
      end
    else
      fdf << field(key, value)
    end
  end

  fdf << footer
  return fdf
end