Class: PdftkForms::Fdf
- Inherits:
-
Object
- Object
- PdftkForms::Fdf
- 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(data = {}, options = {}) ⇒ Fdf
constructor
A new instance of Fdf.
-
#save_to(path) ⇒ Object
write fdf content to path.
-
#to_fdf ⇒ Object
generate FDF content.
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 = {}, = {}) @data = data @options = { :file => nil, :ufile => nil, :id => nil }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/pdftk_forms/fdf.rb', line 9 def @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_fdf ⇒ Object
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 << return fdf end |