fillable-pdf 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 476917341eb1db165e3aa0b7707c1db15ff37da3
4
- data.tar.gz: 2b544131afb874e52e1d67dc0074cc66bafbc9d3
3
+ metadata.gz: 53636c271886fe182d24b56dc716c20a96d4d012
4
+ data.tar.gz: 4f68f2148e8bb842bd4a5fcd0d6bcc962eb2dcff
5
5
  SHA512:
6
- metadata.gz: a59918324b552feb21632ce4f0c132659ba23685836717b9f7fbae4166bca6d80826e16cc1e84cd074155b3be1ee6a17085e2c357ee3308d407b8c80a8ff7c06
7
- data.tar.gz: c61d56797285475ec09473fcd0896721aa84fa0955abee1cc2b848b656687ba4d8d67a847f1201625c23adb8cc451acc1327784a867130eac1119e37ca90923d
6
+ metadata.gz: 8fcfc6cc0bc993c1f53acec746fb9e74d08a1ce38293696c33d1ae9d03629ad0676f02f7e41fe0869ac5548622d213e060a01662b2ebece48d3e6e229af72b19
7
+ data.tar.gz: 19ee774ce229f5ffa5b216e3bd8ba94be134f9f9ebb62a8323ab14c7105e9810e1089e6309e4716b9a9c29cba66fd42868b1175725416159b0466b7cfd45cef4
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'bundler/gem_tasks'
2
- task :default => :spec
2
+ task default: :spec
@@ -11,4 +11,4 @@ require 'fillable-pdf'
11
11
  # Pry.start
12
12
 
13
13
  require 'irb'
14
- IRB.start
14
+ IRB.start
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'fillable-pdf/version'
@@ -17,9 +18,9 @@ Gem::Specification.new do |spec|
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
19
  spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = %w(ext lib)
21
+ spec.require_paths = %w[ext lib]
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.12'
23
- spec.add_development_dependency 'rake', '~> 11.2'
23
+ spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'rake', '~> 12'
24
25
  spec.add_runtime_dependency 'rjb', '~> 1.5'
25
- end
26
+ end
@@ -2,16 +2,13 @@ require 'rjb'
2
2
  require 'securerandom'
3
3
 
4
4
  # http://github.com/itext/itextpdf/releases/latest
5
- Rjb::load(File.expand_path('../ext/itextpdf-5.5.9.jar', __dir__))
6
-
5
+ Rjb.load(File.expand_path('../ext/itext5-itextpdf-5.5.11.jar', __dir__))
7
6
 
8
7
  class FillablePDF
9
-
10
8
  # required Java imports
11
- BYTE_STREAM = Rjb::import('java.io.ByteArrayOutputStream')
12
- FILE_READER = Rjb::import('com.itextpdf.text.pdf.PdfReader')
13
- PDF_STAMPER = Rjb::import('com.itextpdf.text.pdf.PdfStamper')
14
-
9
+ BYTE_STREAM = Rjb.import('java.io.ByteArrayOutputStream')
10
+ FILE_READER = Rjb.import('com.itextpdf.text.pdf.PdfReader')
11
+ PDF_STAMPER = Rjb.import('com.itextpdf.text.pdf.PdfStamper')
15
12
 
16
13
  ##
17
14
  # Opens a given fillable PDF file and prepares it for modification.
@@ -19,23 +16,21 @@ class FillablePDF
19
16
  # @param [String] file the name of the PDF file or file path
20
17
  #
21
18
  def initialize(file)
22
- @file = file
19
+ @file = file
23
20
  @byte_stream = BYTE_STREAM.new
24
21
  @pdf_stamper = PDF_STAMPER.new FILE_READER.new(@file), @byte_stream
25
22
  @form_fields = @pdf_stamper.getAcroFields
26
23
  end
27
24
 
28
-
29
25
  ##
30
26
  # Determines whether the form has any fields.
31
27
  #
32
28
  # @return true if form has fields, false otherwise
33
29
  #
34
- def has_fields?
30
+ def any_fields?
35
31
  num_fields > 0
36
32
  end
37
33
 
38
-
39
34
  ##
40
35
  # Returns the total number of form fields.
41
36
  #
@@ -45,7 +40,6 @@ class FillablePDF
45
40
  @form_fields.getFields.size
46
41
  end
47
42
 
48
-
49
43
  ##
50
44
  # Retrieves the value of a field given its unique field name.
51
45
  #
@@ -57,7 +51,6 @@ class FillablePDF
57
51
  @form_fields.getField key.to_s
58
52
  end
59
53
 
60
-
61
54
  ##
62
55
  # Sets the value of a field given its unique field name and value.
63
56
  #
@@ -68,7 +61,6 @@ class FillablePDF
68
61
  @form_fields.setField key.to_s, value.to_s
69
62
  end
70
63
 
71
-
72
64
  ##
73
65
  # Sets the values of multiple fields given a set of unique field names and values.
74
66
  #
@@ -78,7 +70,6 @@ class FillablePDF
78
70
  fields.each { |key, value| set_field key, value }
79
71
  end
80
72
 
81
-
82
73
  ##
83
74
  # Overwrites the previously opened PDF file and flattens it if requested.
84
75
  #
@@ -90,7 +81,6 @@ class FillablePDF
90
81
  File.rename tmp_file, @file
91
82
  end
92
83
 
93
-
94
84
  ##
95
85
  # Saves the filled out PDF file with a given file and flattens it if requested.
96
86
  #
@@ -98,10 +88,9 @@ class FillablePDF
98
88
  # @param [bool] flatten true if PDF should be flattened, false otherwise
99
89
  #
100
90
  def save_as(file, flatten = false)
101
- File.open(file, 'wb') { |f| f.write finalize flatten and f.close }
91
+ File.open(file, 'wb') { |f| f.write(finalize(flatten)) && f.close }
102
92
  end
103
93
 
104
-
105
94
  private
106
95
 
107
96
  ##
@@ -114,5 +103,4 @@ class FillablePDF
114
103
  @pdf_stamper.close
115
104
  @byte_stream.toByteArray
116
105
  end
117
-
118
- end
106
+ end
@@ -1,3 +1,3 @@
1
1
  module FillablePDF
2
- VERSION = '0.1.1'
3
- end
2
+ VERSION = '0.1.2'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fillable-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Kononov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-18 00:00:00.000000000 Z
11
+ date: 2017-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '1.15'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.2'
33
+ version: '12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '11.2'
40
+ version: '12'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rjb
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - bin/console
70
70
  - bin/setup
71
- - ext/itextpdf-5.5.9.jar
71
+ - ext/itext5-itextpdf-5.5.11.jar
72
72
  - fillable-pdf.gemspec
73
73
  - lib/fillable-pdf.rb
74
74
  - lib/fillable-pdf/version.rb
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.6.6
96
+ rubygems_version: 2.6.11
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Fill out or extract field values from simple fillable PDF forms using iText.
Binary file