Sha256: 720ac9fe98f0ddc8d6d51fa45dda493b58e4f17dbe2d058f7832a2d04698161b

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

module PdftkForms
  class Xfdf
    
    def initialize(data = {})
      @data = data
    end
    
    def to_xfdf
      xfdf = Builder::XmlMarkup.new
      xfdf.instruct!
      xfdf.xfdf(:xmlns => "http://ns.adobe.com/xfdf/", :"xml:space" => "preserve") do
        xfdf.fields do
          @data.each do |key, value|
            if Hash === value
              value.each do |sub_key, sub_value|
                xfdf.field(:name => "#{key}_#{sub_key}") do
                  xfdf.value sub_value
                end
              end
            else
              xfdf.field(:name => key) do
                xfdf.value value
              end
            end
          end
        end
      end
      xfdf
    end
    
    def save_to(path)
      xml = to_xfdf.target!
      (File.open(path, 'w') << xml).close
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pdftk_forms-0.1.0 lib/pdftk_forms/xfdf.rb