class PdfForms::Fdf
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).
Constants
- FOOTER
Public Class Methods
new(data = {}, options = {})
click to toggle source
Calls superclass method
PdfForms::DataFormat::new
# File lib/pdf_forms/fdf.rb, line 11 def initialize(data = {}, options = {}) super end
Private Instance Methods
encode_data(fdf)
click to toggle source
# File lib/pdf_forms/fdf.rb, line 17 def encode_data(fdf) # I have yet to see a version of pdftk which can handle UTF8 input, # so we convert to ISO-8859-15 here, replacing unknown / invalid chars # with the default replacement which is '?'. if fdf.respond_to?(:encode!) # Ruby >= 1.9 fdf.encode!('ISO-8859-15', :invalid => :replace, :undef => :replace) else # pre 1.9 require 'iconv' Iconv.conv('ISO-8859-15//IGNORE', 'utf-8', fdf) end end
field(key, value)
click to toggle source
pp 561 www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf
# File lib/pdf_forms/fdf.rb, line 47 def field(key, value) field = "<<" field << "/T" + "(#{key})" field << "/V" + (Array === value ? "[#{value.map{ |v|"(#{quote(v)})" }.join}]" : "(#{quote(value)})") field << ">>\n" field end
header()
click to toggle source
pp 559 www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf
# File lib/pdf_forms/fdf.rb, line 32 def header header = "%FDF-1.2\n\n1 0 obj\n<<\n/FDF << /Fields 2 0 R" # /F header << "/F (#{options[:file]})" if options[:file] # /UF header << "/UF (#{options[:ufile]})" if options[:ufile] # /ID header << "/ID[" << options[:id].join << "]" if options[:id] header << ">>\n>>\nendobj\n2 0 obj\n[" header end
quote(value)
click to toggle source
# File lib/pdf_forms/fdf.rb, line 55 def quote(value) value.to_s. gsub( /(\\|\(|\))/ ) { '\\' + $1 }. gsub( /\n/, '\r' ) end