fillable-pdf 0.9.5 → 0.9.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/README.md +68 -19
- data/ext/{commons-7.2.3.jar → commons-7.2.4.jar} +0 -0
- data/ext/font-asian-7.2.4.jar +0 -0
- data/ext/{forms-7.2.3.jar → forms-7.2.4.jar} +0 -0
- data/ext/{io-7.2.3.jar → io-7.2.4.jar} +0 -0
- data/ext/{kernel-7.2.3.jar → kernel-7.2.4.jar} +0 -0
- data/ext/{layout-7.2.3.jar → layout-7.2.4.jar} +0 -0
- data/ext/slf4j-api-2.0.4.jar +0 -0
- data/ext/slf4j-simple-2.0.4.jar +0 -0
- data/images/blank.png +0 -0
- data/images/checked.png +0 -0
- data/images/distinct.png +0 -0
- data/lib/fillable-pdf/version.rb +1 -1
- data/lib/fillable-pdf.rb +12 -9
- metadata +14 -11
- data/ext/font-asian-7.2.3.jar +0 -0
- data/ext/slf4j-api-1.7.32.jar +0 -0
- data/ext/slf4j-simple-1.7.32.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8b685f435c8356edc53a47ca0581ae1fa71c57cb23876b12e3ba7bef0d4aa99
|
4
|
+
data.tar.gz: 84f4dcd7ac4d566493dcc37a3ea3e7d776c6f8a28b1129465304ad198c2a7530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575e161cc77a304578997b4d2f967019df98382be944b0fbfd1f6e171e97545bf265a84c2b70a1a80515de520517c303fcfdf27db48ce64c0bae3a292832e6a7
|
7
|
+
data.tar.gz: aaaf3eee62d9886660ca753b3a06495d73ba9092d10a56e415bc5283a0056a9418d53ce9df1bda8d7030ed723e93cd1473a59107515800a6715da05eaacf7da5
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,7 @@
|
|
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
|
+
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/vkononov)
|
9
10
|
|
10
11
|
## Known Issues
|
11
12
|
|
@@ -22,9 +23,35 @@ FillablePDF is an extremely simple and lightweight utility that bridges iText an
|
|
22
23
|
|
23
24
|
4. Read-only, write-protected or encrypted PDF files are currently not supported.
|
24
25
|
|
25
|
-
5. Adobe generated field arrays (i.e. fields with names such as `array.0` or `array.1.0`) are not supported.
|
26
|
+
5. Adobe generated field arrays (i.e. fields with names such as `array.0` or `array.1.0`) are not supported.
|
26
27
|
|
27
28
|
|
29
|
+
## Troubleshooting Issues
|
30
|
+
|
31
|
+
### Blank Fields
|
32
|
+
|
33
|
+
* **Actual Result:**
|
34
|
+
|
35
|
+
![Blank](images/blank.png)
|
36
|
+
|
37
|
+
* **Expected Result:**
|
38
|
+
|
39
|
+
![Blank](images/checked.png)
|
40
|
+
|
41
|
+
If only of the fields are blank, try setting the `generate_appearance` flag to `true` when calling `set_field` or `set_fields`.
|
42
|
+
|
43
|
+
### Invalid Checkbox Appearances
|
44
|
+
|
45
|
+
* **Actual Result:**
|
46
|
+
|
47
|
+
![Blank](images/checked.png)
|
48
|
+
|
49
|
+
* **Expected Result:**
|
50
|
+
|
51
|
+
![Blank](images/distinct.png)
|
52
|
+
|
53
|
+
If your checkboxes are showing incorrectly, it's likely because iText is overwriting your checkbox appearances. Try setting the `generate_appearance` flag to `false` when calling `set_field` or `set_fields`.
|
54
|
+
|
28
55
|
## Installation
|
29
56
|
|
30
57
|
**Prerequisites:** Java SE Development Kit v8, v11
|
@@ -130,19 +157,21 @@ An instance of `FillablePDF` has the following methods at its disposal:
|
|
130
157
|
pdf.num_fields
|
131
158
|
```
|
132
159
|
|
133
|
-
* `field`
|
160
|
+
* `field(key)`
|
134
161
|
*Retrieves the value of a field given its unique field name.*
|
135
162
|
|
136
163
|
```ruby
|
137
164
|
pdf.field(:full_name)
|
165
|
+
pdf.field('full_name')
|
138
166
|
# output example: 'Richard'
|
139
167
|
```
|
140
168
|
|
141
|
-
* `field_type`
|
169
|
+
* `field_type(key)`
|
142
170
|
*Retrieves the string type of a field given its unique field name.*
|
143
171
|
|
144
172
|
```ruby
|
145
173
|
pdf.field_type(:football)
|
174
|
+
pdf.field_type('football')
|
146
175
|
# output example: '/Btn'
|
147
176
|
|
148
177
|
# list of all field types
|
@@ -156,6 +185,7 @@ An instance of `FillablePDF` has the following methods at its disposal:
|
|
156
185
|
|
157
186
|
```ruby
|
158
187
|
pdf.field_type(:football) == Field::BUTTON
|
188
|
+
pdf.field_type('football') == Field::BUTTON
|
159
189
|
```
|
160
190
|
|
161
191
|
* `fields`
|
@@ -166,52 +196,71 @@ An instance of `FillablePDF` has the following methods at its disposal:
|
|
166
196
|
# output example: {first_name: "Richard", last_name: "Rahl"}
|
167
197
|
```
|
168
198
|
|
169
|
-
* `set_field`
|
170
|
-
*Sets the value of a field given its unique field name and value.*
|
199
|
+
* `set_field(key, value, generate_appearance: nil)`
|
200
|
+
*Sets the value of a field given its unique field name and value, with an optional `generate_appearance` directive.*
|
171
201
|
|
172
202
|
```ruby
|
173
203
|
pdf.set_field(:first_name, 'Richard')
|
204
|
+
pdf.set_field('first_name', 'Richard')
|
174
205
|
# result: changes the value of 'first_name' to 'Richard'
|
175
206
|
```
|
176
207
|
|
177
|
-
|
178
|
-
|
208
|
+
Optionally, you can choose to override iText's `generateAppearance` flag to take better control of your field's appearance, using `generate_appearance`. Passing `true` will force the field to generate its own appearance, while setting it to `false` would leave the appearance generation up to the PDF viewer application. Omitting the parameter would allow iText to decide what should happen.
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
pdf.set_field(:first_name, 'Richard', generate_appearance: true)
|
212
|
+
pdf.set_field('first_name', 'Richard', generate_appearance: false)
|
213
|
+
```
|
214
|
+
|
215
|
+
* `def set_fields(fields, generate_appearance: nil)`
|
216
|
+
*Sets the values of multiple fields given a set of unique field names and values, with an optional `generate_appearance` directive.*
|
179
217
|
|
180
218
|
```ruby
|
181
|
-
pdf.set_fields(first_name: 'Richard', last_name: 'Rahl')
|
219
|
+
pdf.set_fields({first_name: 'Richard', last_name: 'Rahl'})
|
182
220
|
# result: changes the values of 'first_name' and 'last_name'
|
183
221
|
```
|
184
222
|
|
185
|
-
|
223
|
+
Optionally, you can choose to override iText's `generateAppearance` flag to take better control of your fields' appearance, using `generate_appearance`. Passing `true` will force the field to generate its own appearance, while setting it to `false` would leave the appearance generation up to the PDF viewer application. Omitting the parameter would allow iText to decide what should happen.
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
pdf.set_fields({first_name: 'Richard', last_name: 'Rahl'}, generate_appearance: true)
|
227
|
+
pdf.set_fields({first_name: 'Richard', last_name: 'Rahl'}, generate_appearance: false)
|
228
|
+
```
|
229
|
+
|
230
|
+
* `set_image(key, file_path)`
|
186
231
|
*Places an image file within the rectangular bounding box of the given form field.*
|
187
232
|
|
188
233
|
```ruby
|
189
234
|
pdf.set_image(:signature, 'signature.png')
|
235
|
+
pdf.set_image('signature', 'signature.png')
|
190
236
|
# result: the image 'signature.png' is shown in the foreground of the form field
|
191
237
|
```
|
192
238
|
|
193
|
-
* `set_image_base64`
|
239
|
+
* `set_image_base64(key, base64_image_data)`
|
194
240
|
*Places a base64 encoded image within the rectangular bounding box of the given form field.*
|
195
241
|
|
196
242
|
```ruby
|
243
|
+
pdf.set_image_base64('signature', 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==')
|
197
244
|
pdf.set_image_base64(:signature, 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==')
|
198
245
|
# result: the base64 encoded image is shown in the foreground of the form field
|
199
246
|
```
|
200
247
|
|
201
|
-
* `rename_field`
|
248
|
+
* `rename_field(old_key, new_key)`
|
202
249
|
*Renames a field given its unique field name and the new field name.*
|
203
250
|
|
204
251
|
```ruby
|
205
252
|
pdf.rename_field(:last_name, :surname)
|
253
|
+
pdf.rename_field('last_name', 'surname')
|
206
254
|
# result: renames field name 'last_name' to 'surname'
|
207
255
|
# NOTE: this action does not take effect until the document is saved
|
208
256
|
```
|
209
257
|
|
210
|
-
* `remove_field`
|
258
|
+
* `remove_field(key)`
|
211
259
|
*Removes a field from the document given its unique field name.*
|
212
260
|
|
213
261
|
```ruby
|
214
262
|
pdf.remove_field(:last_name)
|
263
|
+
pdf.remove_field('last_name')
|
215
264
|
# result: physically removes field 'last_name' from document
|
216
265
|
```
|
217
266
|
|
@@ -231,7 +280,7 @@ An instance of `FillablePDF` has the following methods at its disposal:
|
|
231
280
|
# output example: ["Rahl", "Richard"]
|
232
281
|
```
|
233
282
|
|
234
|
-
* `save`
|
283
|
+
* `save(flatten: false)`
|
235
284
|
*Overwrites the previously opened PDF document and flattens it if requested.*
|
236
285
|
|
237
286
|
```ruby
|
@@ -241,7 +290,7 @@ An instance of `FillablePDF` has the following methods at its disposal:
|
|
241
290
|
# result: document is saved with flattening
|
242
291
|
```
|
243
292
|
|
244
|
-
* `save_as`
|
293
|
+
* `save_as(file_path, flatten: false)`
|
245
294
|
*Saves the filled out PDF document in a given path and flattens it if requested.*
|
246
295
|
|
247
296
|
```ruby
|
@@ -343,8 +392,8 @@ end
|
|
343
392
|
puts
|
344
393
|
|
345
394
|
# setting form fields
|
346
|
-
pdf.set_fields(first_name: 'Richard', last_name: 'Rahl')
|
347
|
-
pdf.set_fields(football: 'Yes', baseball: 'Yes', basketball: 'Yes', nascar: 'Yes', hockey: 'Yes')
|
395
|
+
pdf.set_fields({first_name: 'Richard', last_name: 'Rahl'})
|
396
|
+
pdf.set_fields({football: 'Yes', baseball: 'Yes', basketball: 'Yes', nascar: 'Yes', hockey: 'Yes', rugby: 'Yes'}, generate_appearance: false)
|
348
397
|
pdf.set_field(:date, Time.now.strftime('%B %e, %Y'))
|
349
398
|
pdf.set_field(:newsletter, 'Off') # uncheck the checkbox
|
350
399
|
pdf.set_field(:language, 'dart') # select a radio button option
|
@@ -367,7 +416,7 @@ puts "Values: #{pdf.values}"
|
|
367
416
|
puts
|
368
417
|
|
369
418
|
# Checking field type
|
370
|
-
if pdf.field_type(:
|
419
|
+
if pdf.field_type(:rugby) == Field::BUTTON
|
371
420
|
puts "Field 'football' is of type BUTTON"
|
372
421
|
else
|
373
422
|
puts "Field 'football' is not of type BUTTON"
|
@@ -382,8 +431,8 @@ puts "Renamed field 'last_name' to 'surname'"
|
|
382
431
|
puts
|
383
432
|
|
384
433
|
# Removing field
|
385
|
-
pdf.remove_field :
|
386
|
-
puts "Removed field '
|
434
|
+
pdf.remove_field :marketing
|
435
|
+
puts "Removed field 'marketing'"
|
387
436
|
|
388
437
|
# saving the filled out PDF in another file
|
389
438
|
pdf.save_as('output.pdf')
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/images/blank.png
ADDED
Binary file
|
data/images/checked.png
ADDED
Binary file
|
data/images/distinct.png
ADDED
Binary file
|
data/lib/fillable-pdf/version.rb
CHANGED
data/lib/fillable-pdf.rb
CHANGED
@@ -87,12 +87,14 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
|
|
87
87
|
#
|
88
88
|
# @param [String|Symbol] key the field name
|
89
89
|
# @param [String|Symbol] value the field value
|
90
|
+
# @param [NilClass|TrueClass|FalseClass] generate_appearance true to generate appearance, false to let the PDF viewer application generate form field appearance, nil (default) to let iText decide what's appropriate
|
90
91
|
#
|
91
|
-
def set_field(key, value)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
def set_field(key, value, generate_appearance: nil)
|
93
|
+
if generate_appearance.nil?
|
94
|
+
pdf_field(key).setValue(value.to_s)
|
95
|
+
else
|
96
|
+
pdf_field(key).setValue(value.to_s, generate_appearance)
|
97
|
+
end
|
96
98
|
end
|
97
99
|
|
98
100
|
##
|
@@ -157,9 +159,10 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
|
|
157
159
|
# Sets the values of multiple fields given a set of unique field names and values.
|
158
160
|
#
|
159
161
|
# @param [Hash] fields the set of field names and values
|
162
|
+
# @param [NilClass|TrueClass|FalseClass] generate_appearance true to generate appearance, false to let the PDF viewer application generate form field appearance, nil (default) to let iText decide what's appropriate
|
160
163
|
#
|
161
|
-
def set_fields(fields)
|
162
|
-
fields.each { |key, value| set_field key, value }
|
164
|
+
def set_fields(fields, generate_appearance: nil)
|
165
|
+
fields.each { |key, value| set_field key, value, generate_appearance: generate_appearance }
|
163
166
|
end
|
164
167
|
|
165
168
|
##
|
@@ -220,7 +223,7 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
|
|
220
223
|
# Saves the filled out PDF document in a given path and flattens it if requested.
|
221
224
|
#
|
222
225
|
# @param [String] file_path the name of the PDF file or file path
|
223
|
-
# @param [
|
226
|
+
# @param [TrueClass|FalseClass] flatten true if PDF should be flattened, false otherwise
|
224
227
|
#
|
225
228
|
def save_as(file_path, flatten: false)
|
226
229
|
if @file_path == file_path
|
@@ -245,7 +248,7 @@ class FillablePDF # rubocop:disable Metrics/ClassLength
|
|
245
248
|
##
|
246
249
|
# Writes the contents of the modified fields to the previously opened PDF file.
|
247
250
|
#
|
248
|
-
# @param [
|
251
|
+
# @param [TrueClass|FalseClass] flatten: true if PDF should be flattened, false otherwise
|
249
252
|
#
|
250
253
|
def finalize(flatten: false)
|
251
254
|
@pdf_form.flattenFields if flatten
|
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.5
|
4
|
+
version: 0.9.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Kononov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -154,15 +154,18 @@ files:
|
|
154
154
|
- Rakefile
|
155
155
|
- bin/console
|
156
156
|
- bin/setup
|
157
|
-
- ext/commons-7.2.
|
158
|
-
- ext/font-asian-7.2.
|
159
|
-
- ext/forms-7.2.
|
160
|
-
- ext/io-7.2.
|
161
|
-
- ext/kernel-7.2.
|
162
|
-
- ext/layout-7.2.
|
163
|
-
- ext/slf4j-api-
|
164
|
-
- ext/slf4j-simple-
|
157
|
+
- ext/commons-7.2.4.jar
|
158
|
+
- ext/font-asian-7.2.4.jar
|
159
|
+
- ext/forms-7.2.4.jar
|
160
|
+
- ext/io-7.2.4.jar
|
161
|
+
- ext/kernel-7.2.4.jar
|
162
|
+
- ext/layout-7.2.4.jar
|
163
|
+
- ext/slf4j-api-2.0.4.jar
|
164
|
+
- ext/slf4j-simple-2.0.4.jar
|
165
165
|
- fillable-pdf.gemspec
|
166
|
+
- images/blank.png
|
167
|
+
- images/checked.png
|
168
|
+
- images/distinct.png
|
166
169
|
- lib/field.rb
|
167
170
|
- lib/fillable-pdf.rb
|
168
171
|
- lib/fillable-pdf/itext.rb
|
@@ -190,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
193
|
version: '0'
|
191
194
|
requirements:
|
192
195
|
- JDK 8.x - 11.x
|
193
|
-
rubygems_version: 3.
|
196
|
+
rubygems_version: 3.3.7
|
194
197
|
signing_key:
|
195
198
|
specification_version: 4
|
196
199
|
summary: Fill out or extract field values from simple fillable PDF forms using iText.
|
data/ext/font-asian-7.2.3.jar
DELETED
Binary file
|
data/ext/slf4j-api-1.7.32.jar
DELETED
Binary file
|
data/ext/slf4j-simple-1.7.32.jar
DELETED
Binary file
|