pdf-forms 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pdf_forms/pdf.rb CHANGED
@@ -4,6 +4,7 @@ module PdfForms
4
4
 
5
5
  def initialize(path, pdftk)
6
6
  @path = path
7
+ raise IOError unless File.readable?(path)
7
8
  @pdftk = pdftk
8
9
  end
9
10
 
@@ -8,7 +8,7 @@ module PdfForms
8
8
 
9
9
  attr_reader :pdftk, :options
10
10
 
11
- # PdftkWrapper.new('/usr/bin/pdftk', :encrypt => true, :encrypt_options => 'allow Printing')
11
+ # PdftkWrapper.new('/usr/bin/pdftk', :flatten => true, :encrypt => true, :encrypt_options => 'allow Printing')
12
12
  def initialize(pdftk_path, options = {})
13
13
  @pdftk = pdftk_path
14
14
  @options = options
@@ -20,7 +20,7 @@ module PdfForms
20
20
  tmp = Tempfile.new('pdf_forms-fdf')
21
21
  tmp.close
22
22
  fdf.save_to tmp.path
23
- command = pdftk_command %Q("#{template}"), 'fill_form', tmp.path, 'output', destination, 'flatten', encrypt_options(tmp.path)
23
+ command = pdftk_command %Q("#{template}"), 'fill_form', %Q("#{tmp.path}"), 'output', %Q("#{destination}"), add_options(tmp.path)
24
24
  output = %x{#{command}}
25
25
  unless File.readable?(destination) && File.size(destination) > 0
26
26
  raise PdftkError.new("failed to fill form with command\n#{command}\ncommand output was:\n#{output}")
@@ -43,17 +43,31 @@ module PdfForms
43
43
  %x{#{pdftk_command args}}
44
44
  end
45
45
 
46
+ def cat(*files,output)
47
+ files = files[0] if files[0].class == Array
48
+ input = files.map{|f| %Q("#{f}")}
49
+ call_pdftk(*input,'output',output)
50
+ end
51
+
46
52
  protected
47
53
 
48
54
  def pdftk_command(*args)
49
55
  "#{pdftk} #{args.flatten.compact.join ' '} 2>&1"
50
56
  end
51
57
 
52
- def encrypt_options(pwd)
58
+ def add_options(pwd)
59
+ return if options.empty?
60
+ opt_args = []
61
+ if options[:flatten]
62
+ opt_args << 'flatten'
63
+ end
53
64
  if options[:encrypt]
54
- ['encrypt_128bit', 'owner_pw', pwd, options[:encrypt_options]]
65
+ opt_args.concat ['encrypt_128bit', 'owner_pw', pwd, options[:encrypt_options]]
55
66
  end
67
+ opt_args
56
68
  end
57
69
 
70
+
71
+
58
72
  end
59
73
  end
@@ -1,3 +1,3 @@
1
1
  module PdfForms
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pdf-forms
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jens Kr\xC3\xA4mer"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-23 00:00:00 Z
13
+ date: 2012-07-04 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: Fill out PDF forms with pdftk (http://www.accesspdf.com/pdftk/).