fillable-pdf 0.9.1 → 0.9.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
  SHA256:
3
- metadata.gz: 998124f748072a08e1a2f98593b85ba4297952c414bb800c7f05df607d76d1a7
4
- data.tar.gz: d9f16c8942b1c167b476bcc5c630724f631c40285fe05cae20894d542b2daeb7
3
+ metadata.gz: 389bff629090f3998b0981c03d347801d3dde03b7a1e829634980a38524cc7c4
4
+ data.tar.gz: c23c74c352cd65c434cca51056276757c6e7d0f217119d9a2de42bc76203db92
5
5
  SHA512:
6
- metadata.gz: 8e864663a4319fc61ee01448839615ab6125960c5e7a4a39585baa0ce14a339701b748332ffe7dd35bcf7a69fbcc271435e883ee8be86438b818d00d8a034595
7
- data.tar.gz: 485287c89ed9073a01b97afc72d1ab96eec27b2024891c90b69fb2243d25409b14b22b76046ec0fcd2b4b2ed27262b8752f9d0037baff3bcf7a7004617ac83a3
6
+ metadata.gz: dfb50d0139200dce237e1074496acbc3b24cb0b0b89884a233763c988892b8700cd597433989666ba68e3edb1dd20afb4d451b56644002f19115e18359f9314f
7
+ data.tar.gz: 5a9e3d9341305c82a8df63215e02d4e9c590a4e0ef405a0c5a5748ec49f7a9c46284b8dace44907c3adbc2792f516e61e67f5a6c07b91375979ecb3f0b6d362f
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  require:
2
+ - rubocop-md
2
3
  - rubocop-minitest
3
4
  - rubocop-performance
4
5
  - rubocop-rake
@@ -8,9 +9,20 @@ AllCops:
8
9
  Exclude:
9
10
  - .git/**/*
10
11
 
12
+ Gemspec/RequiredRubyVersion:
13
+ Enabled: false
14
+
11
15
  Layout/EmptyLineAfterGuardClause:
12
16
  Enabled: false
13
17
 
18
+ Layout/IndentationConsistency:
19
+ Exclude:
20
+ - README.md
21
+
22
+ Layout/InitialIndentation:
23
+ Exclude:
24
+ - README.md
25
+
14
26
  Layout/LineLength:
15
27
  Exclude:
16
28
  - fillable-pdf.gemspec
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 3.0.0
6
+ - 3.0.2
7
7
  jdk:
8
8
  - openjdk8
9
9
  before_install:
data/README.md CHANGED
@@ -4,38 +4,105 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/fillable-pdf.svg)](https://rubygems.org/gems/fillable-pdf)
5
5
  [![Build Status](https://api.travis-ci.org/vkononov/fillable-pdf.svg?branch=master)](http://travis-ci.org/vkononov/fillable-pdf)
6
6
 
7
- FillablePDF is an extremely simple and lightweight utility that bridges iText and Ruby in order to fill out fillable PDF forms or extract field values from previously filled out PDF forms.
7
+ FillablePDF is an extremely simple and lightweight utility that bridges iText and Ruby in order to fill out fillable PDF forms or extract field values from previously filled out PDF forms.
8
+
8
9
 
9
10
  ## Known Issues
10
11
 
11
- If the gem hangs in `development`, removing the following gems may fix the issue:
12
+ 1. This gem currently does not work with Phusion Passenger's [smart spawning](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#the-smart-spawning-method). Please see [Deployment with Phusion Passenger + Nginx](#deployment-with-phusion-passenger--nginx) for more information.
12
13
 
13
- ```ruby
14
- gem 'spring'
15
- gem 'spring-watcher-listen'
14
+ 2. If the gem hangs in `development`, removing the following gems may fix the issue:
15
+
16
+ ```ruby
17
+ gem 'spring'
18
+ gem 'spring-watcher-listen'
19
+ ```
20
+
21
+
22
+ ## Deployment with Heroku
23
+
24
+ When deploying to Heroku, be sure to install the following build packs (in this order):
25
+
26
+ ```bash
27
+ heroku buildpacks:add heroku/jvm
28
+ heroku buildpacks:add heroku/ruby
29
+ ```
30
+
31
+ ## Deployment with Phusion Passenger + Nginx
32
+
33
+ The way the gem is currently built makes it [fundamentally incompatible](https://github.com/phusion/passenger/issues/223#issuecomment-44504029) with Phusion Passenger's [smart spawning](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#the-smart-spawning-method). You must turn off smart spawning, or else your application will freeze as soon Ruby tries to access the Java bridge.
34
+
35
+ Below is an example of a simple Nginx virtual host configuration (note the use of `passenger_spawn_method`):
36
+
37
+ ```nginx
38
+ server {
39
+ server_name my-rails-app.com;
40
+ listen 443 ssl http2;
41
+ listen [::]:443 ssl http2;
42
+ passenger_enabled on;
43
+ passenger_spawn_method direct;
44
+ root /home/system/my-rails-app/public;
45
+ }
46
+ ```
47
+
48
+ If you absolutely must have smart spawning, I recommend using `fillable-pdf` as a service that runs independently of your Rails application.
49
+
50
+
51
+ ## Deployment with Puma + Nginx
52
+
53
+ In order to use Puma in production, you need to configure a reverse proxy in your Nginx virtual host. Here is simple naive example:
54
+
55
+ ```nginx
56
+ server {
57
+ server_name my-rails-app.com;
58
+ listen 443 ssl http2;
59
+ listen [::]:443 ssl http2;
60
+ location / {
61
+ proxy_pass http://127.0.0.1:8888;
62
+ proxy_redirect off;
63
+ proxy_set_header Connection "upgrade";
64
+ proxy_set_header Host $http_host;
65
+ proxy_set_header Upgrade $http_upgrade;
66
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
67
+ proxy_set_header X-Forwarded-Proto https;
68
+ proxy_set_header X-Real-IP $remote_addr;
69
+ }
70
+ }
16
71
  ```
17
72
 
18
- If the gem hangs in `production`, you could try to use `puma` with a reverse proxy to host the application.
73
+ Then you'll have to start Puma in production daemon mode as follows:
74
+
75
+ ```bash
76
+ RAILS_ENV=production bin/rails server -p 8888 --daemon
77
+ ```
78
+
79
+ Naturally, there are many downsides (in terms of efficiency, scalability, security, etc) to running your application in production in this manner, so please use the above as an example only.
19
80
 
20
81
 
21
82
  ## Installation
22
83
 
23
84
  **Ensure that your `JAVA_HOME` variable is set before installing this gem (see examples below).**
24
-
25
- * OSX: `/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home`
85
+
86
+ * OSX: `/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home`
26
87
  * Ubuntu/CentOS: `/usr/lib/jvm/java-1.8.0-openjdk`
27
88
 
28
89
  Add this line to your application's Gemfile:
29
90
 
30
- gem 'fillable-pdf'
91
+ ```ruby
92
+ gem 'fillable-pdf'
93
+ ```
31
94
 
32
95
  And then execute:
33
96
 
34
- bundle
97
+ ```bash
98
+ bundle
99
+ ```
35
100
 
36
101
  Or install it yourself as:
37
102
 
38
- gem install fillable-pdf
103
+ ```bash
104
+ gem install fillable-pdf
105
+ ```
39
106
 
40
107
  If you are using this gem in a script, you need to require it manually:
41
108
 
@@ -57,127 +124,171 @@ pdf = FillablePDF.new 'input.pdf'
57
124
  pdf.close
58
125
  ```
59
126
 
60
- ## Instance Methods
127
+ ### Checking / Unchecking Checkboxes
128
+
129
+ Use the values `'Yes'` and `'Off'` to check and uncheck checkboxes, respectively. For example:
130
+
131
+ ```ruby
132
+ pdf.set_field(:newsletter, 'Yes')
133
+ pdf.set_field(:newsletter, 'Off')
134
+ ```
135
+
136
+ ### Checking / Unchecking Radio Buttons
137
+
138
+ Suppose you have the following a radio button field name `language` with the following options:
139
+
140
+ - Ruby (`ruby`)
141
+ - Python (`python`)
142
+ - Dart (`dart`)
143
+ - Other (`other`)
144
+
145
+ To select one of these options (or change the current option) use:
146
+
147
+ ```ruby
148
+ pdf.set_field(:language, 'dart')
149
+ ```
150
+
151
+ To unset the radio button use the `'Off'` string:
152
+
153
+ ```ruby
154
+ pdf.set_field(:language, 'Off')
155
+ ```
156
+
157
+ ### Instance Methods
61
158
 
62
159
  An instance of `FillablePDF` has the following methods at its disposal:
63
160
 
64
161
  * `any_fields?`
65
- *Determines whether the form has any fields.*
66
- ```ruby
67
- pdf.any_fields?
68
- # output example: true
69
- ```
162
+ *Determines whether the form has any fields.*
163
+
164
+ ```ruby
165
+ pdf.any_fields?
166
+ # output example: true
167
+ ```
70
168
 
71
169
  * `num_fields`
72
- *Returns the total number of fillable form fields.*
73
- ```ruby
74
- # output example: 10
75
- pdf.num_fields
76
- ```
170
+ *Returns the total number of fillable form fields.*
171
+
172
+ ```ruby
173
+ # output example: 10
174
+ pdf.num_fields
175
+ ```
77
176
 
78
177
  * `field`
79
- *Retrieves the value of a field given its unique field name.*
80
- ```ruby
81
- pdf.field(:full_name)
82
- # output example: 'Richard'
83
- ```
178
+ *Retrieves the value of a field given its unique field name.*
179
+
180
+ ```ruby
181
+ pdf.field(:full_name)
182
+ # output example: 'Richard'
183
+ ```
84
184
 
85
185
  * `field_type`
86
- *Retrieves the numeric type of a field given its unique field name.*
87
- ```ruby
88
- pdf.field_type(:football)
89
- # output example: 4
90
-
91
- # list of all field types
92
- Field::BUTTON
93
- Field::CHOICE
94
- Field::SIGNATURE
95
- Field::TEXT
96
- ```
186
+ *Retrieves the numeric type of a field given its unique field name.*
187
+
188
+ ```ruby
189
+ pdf.field_type(:football)
190
+ # output example: '/Btn'
191
+
192
+ # list of all field types
193
+ Field::BUTTON ('/Btn')
194
+ Field::CHOICE ('/Ch')
195
+ Field::SIGNATURE ('/Sig')
196
+ Field::TEXT ('/Tx')
197
+ ```
97
198
 
98
199
  * `fields`
99
- *Retrieves a hash of all fields and their values.*
100
- ```ruby
101
- pdf.fields
102
- # output example: {first_name: "Richard", last_name: "Rahl"}
103
- ```
200
+ *Retrieves a hash of all fields and their values.*
201
+
202
+ ```ruby
203
+ pdf.fields
204
+ # output example: {first_name: "Richard", last_name: "Rahl"}
205
+ ```
104
206
 
105
207
  * `set_field`
106
- *Sets the value of a field given its unique field name and value.*
107
- ```ruby
108
- pdf.set_field(:first_name, 'Richard')
109
- # result: changes the value of 'first_name' to 'Richard'
110
- ```
208
+ *Sets the value of a field given its unique field name and value.*
209
+
210
+ ```ruby
211
+ pdf.set_field(:first_name, 'Richard')
212
+ # result: changes the value of 'first_name' to 'Richard'
213
+ ```
111
214
 
112
215
  * `set_fields`
113
- *Sets the values of multiple fields given a set of unique field names and values.*
114
- ```ruby
115
- pdf.set_fields(first_name: 'Richard', last_name: 'Rahl')
116
- # result: changes the values of 'first_name' and 'last_name'
117
- ```
216
+ *Sets the values of multiple fields given a set of unique field names and values.*
217
+
218
+ ```ruby
219
+ pdf.set_fields(first_name: 'Richard', last_name: 'Rahl')
220
+ # result: changes the values of 'first_name' and 'last_name'
221
+ ```
118
222
 
119
223
  * `rename_field`
120
- *Renames a field given its unique field name and the new field name.*
121
- ```ruby
122
- pdf.rename_field(:last_name, :surname)
123
- # result: renames field name 'last_name' to 'surname'
124
- # NOTE: this action does not take effect until the document is saved
125
- ```
224
+ *Renames a field given its unique field name and the new field name.*
225
+
226
+ ```ruby
227
+ pdf.rename_field(:last_name, :surname)
228
+ # result: renames field name 'last_name' to 'surname'
229
+ # NOTE: this action does not take effect until the document is saved
230
+ ```
126
231
 
127
232
  * `remove_field`
128
- *Removes a field from the document given its unique field name.*
129
- ```ruby
130
- pdf.remove_field(:last_name)
131
- # result: physically removes field 'last_name' from document
132
- ```
233
+ *Removes a field from the document given its unique field name.*
234
+
235
+ ```ruby
236
+ pdf.remove_field(:last_name)
237
+ # result: physically removes field 'last_name' from document
238
+ ```
133
239
 
134
240
  * `names`
135
- *Returns a list of all field keys used in the document.*
136
- ```ruby
137
- pdf.names
138
- # output example: [:first_name, :last_name]
139
- ```
241
+ *Returns a list of all field keys used in the document.*
242
+
243
+ ```ruby
244
+ pdf.names
245
+ # output example: [:first_name, :last_name]
246
+ ```
140
247
 
141
248
  * `values`
142
- *Returns a list of all field values used in the document.*
143
- ```ruby
144
- pdf.values
145
- # output example: ["Rahl", "Richard"]
146
- ```
249
+ *Returns a list of all field values used in the document.*
250
+
251
+ ```ruby
252
+ pdf.values
253
+ # output example: ["Rahl", "Richard"]
254
+ ```
147
255
 
148
256
  * `save`
149
- *Overwrites the previously opened PDF document and flattens it if requested.*
150
- ```ruby
151
- pdf.save
152
- # result: document is saved without flatenning
153
- pdf.save_as(flatten: true)
154
- # result: document is saved with flatenning
155
- ```
257
+ *Overwrites the previously opened PDF document and flattens it if requested.*
258
+
259
+ ```ruby
260
+ pdf.save
261
+ # result: document is saved without flattening
262
+ pdf.save_as(flatten: true)
263
+ # result: document is saved with flattening
264
+ ```
156
265
 
157
266
  * `save_as`
158
- *Saves the filled out PDF document in a given path and flattens it if requested.*
159
- ```ruby
160
- pdf.save_as('output.pdf')
161
- # result: document is saved in a given path without flatenning
162
- pdf.save_as('output.pdf', flatten: true)
163
- # result: document is saved in a given path with flatenning
164
- ```
267
+ *Saves the filled out PDF document in a given path and flattens it if requested.*
268
+
269
+ ```ruby
270
+ pdf.save_as('output.pdf')
271
+ # result: document is saved in a given path without flattening
272
+ pdf.save_as('output.pdf', flatten: true)
273
+ # result: document is saved in a given path with flattening
274
+ ```
165
275
 
166
- **NOTE:** Saving the file automatically closes the input file, so you would need to reinitialize the `FillabePDF` class before making any more changes or saving another copy.
276
+ **NOTE:** Saving the file automatically closes the input file, so you would need to reinitialize the `FillabePDF` class before making any more changes or saving another copy.
167
277
 
168
278
  * `close`
169
- *Closes the PDF document discarding all unsaved changes.*
170
- ```ruby
171
- pdf.close
172
- # result: document is closed
173
- ```
279
+ *Closes the PDF document discarding all unsaved changes.*
280
+
281
+ ```ruby
282
+ pdf.close
283
+ # result: document is closed
284
+ ```
174
285
 
175
286
  ## Example
176
287
 
177
288
  The following example [example.rb](example/run.rb) and the input file [input.pdf](example/input.pdf) are located in the `test` directory. It uses all of the methods that are described above and generates the output files [output.pdf](example/output.pdf) and [output.flat.pdf](example/output.flat.pdf).
178
289
 
179
290
  ```ruby
180
- require 'fillable-pdf'
291
+ require_relative '../lib/fillable-pdf'
181
292
 
182
293
  # opening a fillable PDF
183
294
  pdf = FillablePDF.new('input.pdf')
@@ -196,6 +307,8 @@ pdf.set_fields(first_name: 'Richard', last_name: 'Rahl')
196
307
  pdf.set_fields(football: 'Yes', baseball: 'Yes',
197
308
  basketball: 'Yes', nascar: 'Yes', hockey: 'Yes')
198
309
  pdf.set_field(:date, Time.now.strftime('%B %e, %Y'))
310
+ pdf.set_field(:newsletter, 'Off') # uncheck the checkbox
311
+ pdf.set_field(:language, 'dart') # select a radio button option
199
312
 
200
313
  # list of fields
201
314
  puts "Fields hash: #{pdf.fields}"
@@ -248,14 +361,14 @@ pdf.close
248
361
 
249
362
  The example above produces the following output and also generates the output file [output.pdf](example/output.pdf).
250
363
 
251
- ```
252
- The form has a total of 8 fields.
364
+ ```text
365
+ The form has a total of 14 fields.
253
366
 
254
- Fields hash: {:last_name=>"Rahl", :first_name=>"Richard", :football=>"Yes", :baseball=>"Yes", :basketball=>"Yes", :nascar=>"Yes", :hockey=>"Yes", :date=>"August 30, 2019"}
367
+ Fields hash: {:last_name=>"Rahl", :first_name=>"Richard", :football=>"Yes", :baseball=>"Yes", :basketball=>"Yes", :hockey=>"Yes", :date=>"November 15, 2021", :newsletter=>"Off", :nascar=>"Yes", :language=>"dart", :"language.1"=>"dart", :"language.2"=>"dart", :"language.3"=>"dart", :"language.4"=>"dart"}
255
368
 
256
- Keys: [:last_name, :first_name, :football, :baseball, :basketball, :nascar, :hockey, :date]
369
+ Keys: [:last_name, :first_name, :football, :baseball, :basketball, :hockey, :date, :newsletter, :nascar, :language, :"language.1", :"language.2", :"language.3", :"language.4"]
257
370
 
258
- Values: ["Rahl", "Richard", "Yes", "Yes", "Yes", "Yes", "Yes", "August 30, 2019"]
371
+ Values: ["Rahl", "Richard", "Yes", "Yes", "Yes", "Yes", "November 15, 2021", "Off", "Yes", "dart", "dart", "dart", "dart", "dart"]
259
372
 
260
373
  Field 'football' is of type BUTTON
261
374
 
Binary file
data/ext/io-7.1.17.jar ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
data/fillable-pdf.gemspec CHANGED
@@ -30,5 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'rubocop-performance'
31
31
  spec.add_development_dependency 'rubocop-rake'
32
32
 
33
- spec.add_runtime_dependency 'rjb', '~> 1.6'
33
+ spec.add_runtime_dependency 'rjb', '1.6.2'
34
+
35
+ spec.metadata = {
36
+ 'rubygems_mfa_required' => 'true'
37
+ }
34
38
  end
@@ -1,3 +1,3 @@
1
1
  class FillablePDF
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
data/lib/fillable-pdf.rb CHANGED
@@ -22,7 +22,7 @@ class FillablePDF
22
22
  @file_path = file_path
23
23
  begin
24
24
  @byte_stream = BYTE_STREAM.new
25
- @pdf_reader = PDF_READER.new @file_path
25
+ @pdf_reader = PDF_READER.new @file_path.to_s
26
26
  @pdf_writer = PDF_WRITER.new @byte_stream
27
27
  @pdf_doc = PDF_DOCUMENT.new @pdf_reader, @pdf_writer
28
28
  @pdf_form = PDF_ACRO_FORM.getAcroForm(@pdf_doc, true)
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.9.1
4
+ version: 0.9.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: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: rjb
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: '1.6'
131
+ version: 1.6.2
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: '1.6'
138
+ version: 1.6.2
139
139
  description: FillablePDF is an extremely simple and lightweight utility that bridges
140
140
  iText and Ruby in order to fill out fillable PDF forms or extract field values from
141
141
  previously filled out PDF forms.
@@ -154,13 +154,13 @@ files:
154
154
  - Rakefile
155
155
  - bin/console
156
156
  - bin/setup
157
- - ext/font-asian-7.1.12.jar
158
- - ext/forms-7.1.12.jar
159
- - ext/io-7.1.12.jar
160
- - ext/kernel-7.1.12.jar
161
- - ext/layout-7.1.12.jar
162
- - ext/slf4j-api-1.7.29.jar
163
- - ext/slf4j-simple-1.7.29.jar
157
+ - ext/font-asian-7.1.17.jar
158
+ - ext/forms-7.1.17.jar
159
+ - ext/io-7.1.17.jar
160
+ - ext/kernel-7.1.17.jar
161
+ - ext/layout-7.1.17.jar
162
+ - ext/slf4j-api-1.7.32.jar
163
+ - ext/slf4j-simple-1.7.32.jar
164
164
  - fillable-pdf.gemspec
165
165
  - lib/field.rb
166
166
  - lib/fillable-pdf.rb
@@ -170,7 +170,8 @@ files:
170
170
  homepage: https://github.com/vkononov/fillable-pdf
171
171
  licenses:
172
172
  - MIT
173
- metadata: {}
173
+ metadata:
174
+ rubygems_mfa_required: 'true'
174
175
  post_install_message:
175
176
  rdoc_options: []
176
177
  require_paths:
@@ -187,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
188
  - !ruby/object:Gem::Version
188
189
  version: '0'
189
190
  requirements: []
190
- rubygems_version: 3.2.3
191
+ rubygems_version: 3.2.22
191
192
  signing_key:
192
193
  specification_version: 4
193
194
  summary: Fill out or extract field values from simple fillable PDF forms using iText.
data/ext/forms-7.1.12.jar DELETED
Binary file
data/ext/io-7.1.12.jar DELETED
Binary file
Binary file
Binary file
Binary file
Binary file