fillable-pdf 0.9.3 → 0.9.5

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: 7043c6e7b7149563d54e87952727cbd2b769d7ab6cbdf6eebfbea91c89e0e6f8
4
- data.tar.gz: cad339bef276e6baf84473ff4e496b9e44e2a0ea487262850e27954cc29a4df4
3
+ metadata.gz: 9cc8f575f9b31b18057031e15fc16d37fd65b41e28668bc9e11a8dba241d9722
4
+ data.tar.gz: 74f1e13956bf1c555c449602456fa01c237c0d3853934741f7c03e914c488a42
5
5
  SHA512:
6
- metadata.gz: f5df81f03db25731784a1c16d132d0d08366a60e02374c1c4d16a1611a45520270d5f91c4fb1fa351a1f05f1d2881400e5cf304c2965063b9fc71cbce617edf2
7
- data.tar.gz: 7cedf3ff9e49d09c7d3fc4467baa5ec7f8bf2761bc247dd03b70d0e620cba5d121aedf33e725e8a79088f601ec77282c491447ae5f149d01c316f70bbc7df60f
6
+ metadata.gz: 7543225bc5bacb607026100289a2c3ab349bced197d9077b2f00eb1c2a13c48da21979d007f7c02b1bbbd81caa036102d2ed15e4e1cc0f1b625153f5be90202b
7
+ data.tar.gz: 65d5d86a9e48494a5adcb168e063d0e73e1e4ff8eb85900571341f1c90ed32cc4a24d103c7f455b1a2ebffb8a70832443d5bef09f2779549326ed6c0e0a9f0a5
@@ -0,0 +1,32 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+
6
+ # GitHub recommends pinning actions to a commit SHA.
7
+ # To get a newer version, you will need to update the SHA.
8
+ # You can also reference a tag or branch, but the action may change without warning.
9
+
10
+ name: test
11
+
12
+ on: [push, pull_request]
13
+
14
+ jobs:
15
+ test:
16
+
17
+ runs-on: ubuntu-latest
18
+
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ['3.1', '3.0', '2.7', '2.6', '2.5', '2.4']
22
+
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - name: Set up Ruby ${{ matrix.ruby-version }}
26
+ uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ - name: Install dependencies
30
+ run: bundle install
31
+ - name: Run tests
32
+ run: bundle exec rake test
data/.rubocop.yml CHANGED
@@ -55,5 +55,8 @@ Style/FrozenStringLiteralComment:
55
55
  Style/GuardClause:
56
56
  Enabled: false
57
57
 
58
+ Style/HashSyntax:
59
+ Enabled: false
60
+
58
61
  Style/MutableConstant:
59
62
  Enabled: false
data/README.md CHANGED
@@ -2,90 +2,37 @@
2
2
  # FillablePDF
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/fillable-pdf.svg)](https://rubygems.org/gems/fillable-pdf)
5
- [![Build Status](https://app.travis-ci.com/vkononov/fillable-pdf.svg?branch=master)](http://travis-ci.org/vkononov/fillable-pdf)
5
+ [![Test Status](https://github.com/vkononov/fillable-pdf/actions/workflows/test.yml/badge.svg)](https://github.com/vkononov/fillable-pdf/actions)
6
6
 
7
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
10
  ## Known Issues
11
11
 
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
+ 1. Phusion Passenger's [smart spawning](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#the-smart-spawning-method) is not supported. Please see [Deployment with Phusion Passenger + Nginx](#deployment-with-phusion-passenger--nginx) for more information.
13
13
 
14
- 2. If the gem hangs in `development`, removing the following gems may fix the issue:
14
+ 2. Puma workers (process forking) is not supposed due to an [issue](https://github.com/arton/rjb/issues/88) with the [rjb](https://github.com/arton/rjb) gem dependency.
15
+
16
+ 3. If the gem hangs in `development`, removing the following gems may fix the issue:
15
17
 
16
18
  ```ruby
17
19
  gem 'spring'
18
20
  gem 'spring-watcher-listen'
19
21
  ```
20
22
 
21
- 3. Read-only, write-protected or encrypted PDF files are currently not supported.
22
-
23
- ## Deployment with Heroku
24
-
25
- When deploying to Heroku, be sure to install the following build packs (in this order):
26
-
27
- ```bash
28
- heroku buildpacks:add heroku/jvm
29
- heroku buildpacks:add heroku/ruby
30
- ```
31
-
32
- ## Deployment with Phusion Passenger + Nginx
33
-
34
- 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.
35
-
36
- Below is an example of a simple Nginx virtual host configuration (note the use of `passenger_spawn_method`):
37
-
38
- ```nginx
39
- server {
40
- server_name my-rails-app.com;
41
- listen 443 ssl http2;
42
- listen [::]:443 ssl http2;
43
- passenger_enabled on;
44
- passenger_spawn_method direct;
45
- root /home/system/my-rails-app/public;
46
- }
47
- ```
48
-
49
- If you absolutely must have smart spawning, I recommend using `fillable-pdf` as a service that runs independently of your Rails application.
50
-
51
-
52
- ## Deployment with Puma + Nginx
23
+ 4. Read-only, write-protected or encrypted PDF files are currently not supported.
53
24
 
54
- In order to use Puma in production, you need to configure a reverse proxy in your Nginx virtual host. Here is simple naive example:
55
-
56
- ```nginx
57
- server {
58
- server_name my-rails-app.com;
59
- listen 443 ssl http2;
60
- listen [::]:443 ssl http2;
61
- location / {
62
- proxy_pass http://127.0.0.1:8888;
63
- proxy_redirect off;
64
- proxy_set_header Connection "upgrade";
65
- proxy_set_header Host $http_host;
66
- proxy_set_header Upgrade $http_upgrade;
67
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
68
- proxy_set_header X-Forwarded-Proto https;
69
- proxy_set_header X-Real-IP $remote_addr;
70
- }
71
- }
72
- ```
73
-
74
- Then you'll have to start Puma in production daemon mode as follows:
75
-
76
- ```bash
77
- RAILS_ENV=production bin/rails server -p 8888 --daemon
78
- ```
79
-
80
- 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.
25
+ 5. Adobe generated field arrays (i.e. fields with names such as `array.0` or `array.1.0`) are not supported.
81
26
 
82
27
 
83
28
  ## Installation
84
29
 
85
- **Ensure that your `JAVA_HOME` variable is set before installing this gem (see examples below).**
30
+ **Prerequisites:** Java SE Development Kit v8, v11
86
31
 
87
- * OSX: `/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home`
88
- * Ubuntu/CentOS: `/usr/lib/jvm/java-1.8.0-openjdk`
32
+ - Ensure that your `JAVA_HOME` variable is set before installing this gem (see examples below).
33
+
34
+ * OSX: `/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home`
35
+ * Ubuntu/CentOS: `/usr/lib/jvm/java-1.8.0-openjdk`
89
36
 
90
37
  Add this line to your application's Gemfile:
91
38
 
@@ -192,7 +139,7 @@ An instance of `FillablePDF` has the following methods at its disposal:
192
139
  ```
193
140
 
194
141
  * `field_type`
195
- *Retrieves the numeric type of a field given its unique field name.*
142
+ *Retrieves the string type of a field given its unique field name.*
196
143
 
197
144
  ```ruby
198
145
  pdf.field_type(:football)
@@ -205,6 +152,12 @@ An instance of `FillablePDF` has the following methods at its disposal:
205
152
  Field::TEXT ('/Tx')
206
153
  ```
207
154
 
155
+ You can check the field type by using:
156
+
157
+ ```ruby
158
+ pdf.field_type(:football) == Field::BUTTON
159
+ ```
160
+
208
161
  * `fields`
209
162
  *Retrieves a hash of all fields and their values.*
210
163
 
@@ -308,6 +261,66 @@ An instance of `FillablePDF` has the following methods at its disposal:
308
261
  # result: document is closed
309
262
  ```
310
263
 
264
+
265
+ ## Deployment with Heroku
266
+
267
+ When deploying to Heroku, be sure to install the following build packs (in this order):
268
+
269
+ ```bash
270
+ heroku buildpacks:add heroku/jvm
271
+ heroku buildpacks:add heroku/ruby
272
+ ```
273
+
274
+ ## Deployment with Phusion Passenger + Nginx
275
+
276
+ 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.
277
+
278
+ Below is an example of a simple Nginx virtual host configuration (note the use of `passenger_spawn_method`):
279
+
280
+ ```nginx
281
+ server {
282
+ server_name my-rails-app.com;
283
+ listen 443 ssl http2;
284
+ listen [::]:443 ssl http2;
285
+ passenger_enabled on;
286
+ passenger_spawn_method direct;
287
+ root /home/system/my-rails-app/public;
288
+ }
289
+ ```
290
+
291
+ If you absolutely must have smart spawning, I recommend using `fillable-pdf` as a service that runs independently of your Rails application.
292
+
293
+ ## Deployment with Puma + Nginx
294
+
295
+ In order to use Puma in production, you need to configure a reverse proxy in your Nginx virtual host. Here is simple naive example:
296
+
297
+ ```nginx
298
+ server {
299
+ server_name my-rails-app.com;
300
+ listen 443 ssl http2;
301
+ listen [::]:443 ssl http2;
302
+ location / {
303
+ proxy_pass http://127.0.0.1:8888;
304
+ proxy_redirect off;
305
+ proxy_set_header Connection "upgrade";
306
+ proxy_set_header Host $http_host;
307
+ proxy_set_header Upgrade $http_upgrade;
308
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
309
+ proxy_set_header X-Forwarded-Proto https;
310
+ proxy_set_header X-Real-IP $remote_addr;
311
+ }
312
+ }
313
+ ```
314
+
315
+ Then you'll have to start Puma in production daemon mode as follows:
316
+
317
+ ```bash
318
+ RAILS_ENV=production bin/rails server -p 8888 --daemon
319
+ ```
320
+
321
+ 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.
322
+
323
+
311
324
  ## Example
312
325
 
313
326
  The following [example.rb](example/run.rb) with [input.pdf](example/input.pdf) is located in the [example](example) 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).
Binary file
Binary file
data/ext/io-7.2.3.jar ADDED
Binary file
Binary file
Binary file
data/fillable-pdf.gemspec CHANGED
@@ -30,7 +30,8 @@ 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.2'
33
+ spec.add_runtime_dependency 'rjb', '~> 1.6'
34
+ spec.requirements << 'JDK 8.x - 11.x'
34
35
 
35
36
  spec.metadata = {
36
37
  'rubygems_mfa_required' => 'true'
@@ -8,7 +8,7 @@ module ITEXT
8
8
  ByteArrayOutputStream = Rjb.import 'com.itextpdf.io.source.ByteArrayOutputStream'
9
9
  Canvas = Rjb.import 'com.itextpdf.layout.Canvas'
10
10
  Div = Rjb.import 'com.itextpdf.layout.element.Div'
11
- HorizontalAlignment = Rjb.import 'com.itextpdf.layout.property.HorizontalAlignment'
11
+ HorizontalAlignment = Rjb.import 'com.itextpdf.layout.properties.HorizontalAlignment'
12
12
  Image = Rjb.import 'com.itextpdf.layout.element.Image'
13
13
  ImageDataFactory = Rjb.import 'com.itextpdf.io.image.ImageDataFactory'
14
14
  PdfAcroForm = Rjb.import 'com.itextpdf.forms.PdfAcroForm'
@@ -19,6 +19,6 @@ module ITEXT
19
19
  PdfReader = Rjb.import 'com.itextpdf.kernel.pdf.PdfReader'
20
20
  PdfWriter = Rjb.import 'com.itextpdf.kernel.pdf.PdfWriter'
21
21
  Rectangle = Rjb.import 'com.itextpdf.kernel.geom.Rectangle'
22
- VerticalAlignment = Rjb.import 'com.itextpdf.layout.property.VerticalAlignment'
22
+ VerticalAlignment = Rjb.import 'com.itextpdf.layout.properties.VerticalAlignment'
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  class FillablePDF
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.5'
3
3
  end
data/lib/fillable-pdf.rb CHANGED
@@ -57,7 +57,7 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
57
57
  end
58
58
 
59
59
  ##
60
- # Retrieves the numeric type of a field given its unique field name.
60
+ # Retrieves the string type of a field given its unique field name.
61
61
  #
62
62
  # @param [String|Symbol] key the field name
63
63
  #
@@ -89,7 +89,10 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
89
89
  # @param [String|Symbol] value the field value
90
90
  #
91
91
  def set_field(key, value)
92
- pdf_field(key).setValue(value.to_s)
92
+ # we set generate_appearance to false for buttons to ensure that the chosen
93
+ # appearance for checkboxes (i.e. check, circle, diamond) is not changed
94
+ generate_appearance = field_type(key) != Field::BUTTON
95
+ pdf_field(key).setValue(value.to_s, generate_appearance)
93
96
  end
94
97
 
95
98
  ##
@@ -144,7 +147,7 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
144
147
  #
145
148
  def set_image_base64(key, base64_image_data)
146
149
  tmp_file = SecureRandom.uuid
147
- File.open(tmp_file, 'wb') { |f| f.write(Base64.decode64(base64_image_data)) }
150
+ File.binwrite(tmp_file, Base64.decode64(base64_image_data))
148
151
  set_image(key, tmp_file)
149
152
  ensure
150
153
  FileUtils.rm tmp_file
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.3
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Kononov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2022-09-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.2
131
+ version: '1.6'
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.2
138
+ version: '1.6'
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.
@@ -145,20 +145,21 @@ executables: []
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
+ - ".github/workflows/test.yml"
148
149
  - ".gitignore"
149
150
  - ".rubocop.yml"
150
- - ".travis.yml"
151
151
  - Gemfile
152
152
  - LICENSE.md
153
153
  - README.md
154
154
  - Rakefile
155
155
  - bin/console
156
156
  - bin/setup
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
157
+ - ext/commons-7.2.3.jar
158
+ - ext/font-asian-7.2.3.jar
159
+ - ext/forms-7.2.3.jar
160
+ - ext/io-7.2.3.jar
161
+ - ext/kernel-7.2.3.jar
162
+ - ext/layout-7.2.3.jar
162
163
  - ext/slf4j-api-1.7.32.jar
163
164
  - ext/slf4j-simple-1.7.32.jar
164
165
  - fillable-pdf.gemspec
@@ -187,8 +188,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
188
  - - ">="
188
189
  - !ruby/object:Gem::Version
189
190
  version: '0'
190
- requirements: []
191
- rubygems_version: 3.2.22
191
+ requirements:
192
+ - JDK 8.x - 11.x
193
+ rubygems_version: 3.1.4
192
194
  signing_key:
193
195
  specification_version: 4
194
196
  summary: Fill out or extract field values from simple fillable PDF forms using iText.
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 3.0.3
7
- jdk:
8
- - openjdk8
9
- before_install:
10
- - gem install bundler
data/ext/forms-7.1.17.jar DELETED
Binary file
data/ext/io-7.1.17.jar DELETED
Binary file
Binary file
Binary file