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 +4 -4
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/bin/console +1 -1
- data/ext/itext5-itextpdf-5.5.11.jar +0 -0
- data/fillable-pdf.gemspec +5 -4
- data/lib/fillable-pdf.rb +8 -20
- data/lib/fillable-pdf/version.rb +2 -2
- metadata +8 -8
- data/ext/itextpdf-5.5.9.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53636c271886fe182d24b56dc716c20a96d4d012
|
4
|
+
data.tar.gz: 4f68f2148e8bb842bd4a5fcd0d6bcc962eb2dcff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fcfc6cc0bc993c1f53acec746fb9e74d08a1ce38293696c33d1ae9d03629ad0676f02f7e41fe0869ac5548622d213e060a01662b2ebece48d3e6e229af72b19
|
7
|
+
data.tar.gz: 19ee774ce229f5ffa5b216e3bd8ba94be134f9f9ebb62a8323ab14c7105e9810e1089e6309e4716b9a9c29cba66fd42868b1175725416159b0466b7cfd45cef4
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
task :
|
2
|
+
task default: :spec
|
data/bin/console
CHANGED
Binary file
|
data/fillable-pdf.gemspec
CHANGED
@@ -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
|
21
|
+
spec.require_paths = %w[ext lib]
|
21
22
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
23
|
-
spec.add_development_dependency 'rake', '~>
|
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
|
data/lib/fillable-pdf.rb
CHANGED
@@ -2,16 +2,13 @@ require 'rjb'
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
# http://github.com/itext/itextpdf/releases/latest
|
5
|
-
Rjb
|
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
|
12
|
-
FILE_READER = Rjb
|
13
|
-
PDF_STAMPER = Rjb
|
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
|
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
|
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
|
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
|
data/lib/fillable-pdf/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module FillablePDF
|
2
|
-
VERSION = '0.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.
|
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:
|
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.
|
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.
|
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: '
|
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: '
|
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.
|
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.
|
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.
|
data/ext/itextpdf-5.5.9.jar
DELETED
Binary file
|