pdf-forms 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009-2011 Jens Kraemer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -33,7 +33,7 @@ First get pdftk from http://www.accesspdf.com/pdftk/ and install it.
33
33
 
34
34
  == INSTALL:
35
35
 
36
- $ sudo gem install jkraemer-pdf-forms
36
+ $ gem install pdf-forms
37
37
 
38
38
  == CODE:
39
39
 
@@ -45,25 +45,4 @@ The FDF generation part is a straight port of Steffen Schwigon's PDF::FDF::Simpl
45
45
 
46
46
  == LICENSE:
47
47
 
48
- (The MIT License)
49
-
50
- Copyright (c) 2009 Jens Kraemer
51
-
52
- Permission is hereby granted, free of charge, to any person obtaining
53
- a copy of this software and associated documentation files (the
54
- 'Software'), to deal in the Software without restriction, including
55
- without limitation the rights to use, copy, modify, merge, publish,
56
- distribute, sublicense, and/or sell copies of the Software, and to
57
- permit persons to whom the Software is furnished to do so, subject to
58
- the following conditions:
59
-
60
- The above copyright notice and this permission notice shall be
61
- included in all copies or substantial portions of the Software.
62
-
63
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
64
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
67
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
68
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
69
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48
+ see LICENSE
data/lib/pdf_forms/pdf.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  module PdfForms
2
2
  class Pdf
3
3
  attr_reader :path
4
-
4
+
5
5
  def initialize(path, pdftk)
6
6
  @path = path
7
7
  @pdftk = pdftk
8
8
  end
9
-
9
+
10
10
  def fields
11
11
  @fields ||= read_fields
12
12
  end
13
-
13
+
14
14
  protected
15
-
15
+
16
16
  def read_fields
17
- field_output = @pdftk.call_pdftk "'#{path}'", 'dump_data_fields'
17
+ field_output = @pdftk.call_pdftk %Q("#{path}"), 'dump_data_fields'
18
18
  @fields = field_output.split(/^---\n/).map do |field_text|
19
19
  if field_text =~ /^FieldName: (\w+)$/
20
20
  $1
@@ -22,4 +22,4 @@ module PdfForms
22
22
  end.compact.uniq
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -1,47 +1,59 @@
1
1
  require 'tempfile'
2
2
  module PdfForms
3
+ class PdftkError < StandardError
4
+ end
5
+
3
6
  # Wraps calls to PdfTk
4
7
  class PdftkWrapper
5
-
8
+
6
9
  attr_reader :pdftk, :options
7
-
10
+
8
11
  # PdftkWrapper.new('/usr/bin/pdftk', :encrypt => true, :encrypt_options => 'allow Printing')
9
12
  def initialize(pdftk_path, options = {})
10
13
  @pdftk = pdftk_path
11
14
  @options = options
12
15
  end
13
-
16
+
14
17
  # pdftk.fill_form '/path/to/form.pdf', '/path/to/destination.pdf', :field1 => 'value 1'
15
18
  def fill_form(template, destination, data = {})
16
19
  fdf = Fdf.new(data)
17
20
  tmp = Tempfile.new('pdf_forms-fdf')
18
21
  tmp.close
19
22
  fdf.save_to tmp.path
20
- call_pdftk "'#{template}'", 'fill_form', tmp.path, 'output', destination, 'flatten', encrypt_options(tmp.path)
21
- tmp.unlink
23
+ command = pdftk_command %Q("#{template}"), 'fill_form', tmp.path, 'output', destination, 'flatten', encrypt_options(tmp.path)
24
+ output = %x{#{command}}
25
+ unless File.readable?(destination) && File.size(destination) > 0
26
+ raise PdftkError.new("failed to fill form with command\n#{command}\ncommand output was:\n#{output}")
27
+ end
28
+ ensure
29
+ tmp.unlink if tmp
22
30
  end
23
-
31
+
24
32
  # pdftk.read '/path/to/form.pdf'
25
33
  # returns an instance of PdfForms::Pdf representing the given template
26
34
  def read(path)
27
35
  Pdf.new path, self
28
36
  end
29
-
37
+
30
38
  def get_field_names(template)
31
39
  read(template).fields
32
40
  end
33
-
41
+
34
42
  def call_pdftk(*args)
35
- %x{#{pdftk} #{args.flatten.compact.join ' '}}
43
+ %x{#{pdftk_command args}}
36
44
  end
37
-
45
+
38
46
  protected
39
-
47
+
48
+ def pdftk_command(*args)
49
+ "#{pdftk} #{args.flatten.compact.join ' '} 2>&1"
50
+ end
51
+
40
52
  def encrypt_options(pwd)
41
53
  if options[:encrypt]
42
54
  ['encrypt_128bit', 'owner_pw', pwd, options[:encrypt_options]]
43
55
  end
44
56
  end
45
-
57
+
46
58
  end
47
- end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module PdfForms
2
- VERSION = '0.3.0'
3
- end
2
+ VERSION = '0.3.2'
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.0
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jens Kr\xC3\xA4mer"
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-10 00:00:00 +02:00
14
- default_executable:
13
+ date: 2012-04-23 00:00:00 Z
15
14
  dependencies: []
16
15
 
17
16
  description: Fill out PDF forms with pdftk (http://www.accesspdf.com/pdftk/).
@@ -29,8 +28,8 @@ files:
29
28
  - lib/pdf_forms/pdftk_wrapper.rb
30
29
  - lib/pdf_forms/version.rb
31
30
  - lib/pdf_forms.rb
31
+ - LICENSE
32
32
  - README.rdoc
33
- has_rdoc: true
34
33
  homepage: http://github.com/jkraemer/pdf-forms
35
34
  licenses: []
36
35
 
@@ -54,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
53
  requirements: []
55
54
 
56
55
  rubyforge_project: pdf-forms
57
- rubygems_version: 1.6.2
56
+ rubygems_version: 1.8.21
58
57
  signing_key:
59
58
  specification_version: 3
60
59
  summary: Fill out PDF forms with pdftk (http://www.accesspdf.com/pdftk/).