Class: Nguyen::PdftkWrapper
- Inherits:
-
Object
- Object
- Nguyen::PdftkWrapper
- Defined in:
- lib/nguyen/pdftk_wrapper.rb
Overview
Wraps calls to PdfTk
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pdftk ⇒ Object
readonly
Returns the value of attribute pdftk.
Instance Method Summary collapse
- #call_pdftk(*args) ⇒ Object
- #cat(*files, output) ⇒ Object
-
#fill_form(template, destination, form_data_format) ⇒ Object
pdftk.fill_form ‘/path/to/form.pdf’, ‘/path/to/destination.pdf’, xfdf_or_fdf_object.
- #get_field_names(template) ⇒ Object
-
#initialize(pdftk_path, options = {}) ⇒ PdftkWrapper
constructor
PdftkWrapper.new(‘/usr/bin/pdftk’, :flatten => true, :encrypt => true, :encrypt_options => ‘allow Printing’).
-
#read(path) ⇒ Object
pdftk.read ‘/path/to/form.pdf’ returns an instance of Nguyen::Pdf representing the given template.
Constructor Details
#initialize(pdftk_path, options = {}) ⇒ PdftkWrapper
PdftkWrapper.new(‘/usr/bin/pdftk’, :flatten => true, :encrypt => true, :encrypt_options => ‘allow Printing’)
12 13 14 15 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 12 def initialize(pdftk_path, = {}) @pdftk = pdftk_path @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 9 def @options end |
#pdftk ⇒ Object (readonly)
Returns the value of attribute pdftk.
9 10 11 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 9 def pdftk @pdftk end |
Instance Method Details
#call_pdftk(*args) ⇒ Object
41 42 43 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 41 def call_pdftk(*args) %x{#{pdftk_command args}} end |
#cat(*files, output) ⇒ Object
45 46 47 48 49 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 45 def cat(*files,output) files = files[0] if files[0].class == Array input = files.map{|f| %Q(#{f})} call_pdftk(*input,'output',output) end |
#fill_form(template, destination, form_data_format) ⇒ Object
pdftk.fill_form ‘/path/to/form.pdf’, ‘/path/to/destination.pdf’, xfdf_or_fdf_object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 18 def fill_form(template, destination, form_data_format) tmp = Tempfile.new('pdf_forms-fdf') tmp.close form_data_format.save_to tmp.path command = pdftk_command %Q("#{template}"), 'fill_form', %Q("#{tmp.path}"), 'output', destination, (tmp.path) output = %x{#{command}} unless File.readable?(destination) && File.size(destination) > 0 raise PdftkError.new("failed to fill form with command\n#{command}\ncommand output was:\n#{output}") end ensure tmp.unlink if tmp end |
#get_field_names(template) ⇒ Object
37 38 39 |
# File 'lib/nguyen/pdftk_wrapper.rb', line 37 def get_field_names(template) read(template).fields end |