pdf-forms 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7082ff050aa4f56aa3bfede64817eda71a98d5f7
4
- data.tar.gz: 54078c07d1d53e29858c56daf19ae3ce446ebcd3
2
+ SHA256:
3
+ metadata.gz: ea5359396b316658bbcb179a5a01588e0dc88d49123291e8200e3e90e8ba54eb
4
+ data.tar.gz: ddc02810b4555e4496345b7cceef687287e8ce55131f0b0eb313421d65edcef9
5
5
  SHA512:
6
- metadata.gz: ac501b1ee613c1f21a526bceb24331535eafb017e71d8935cb6a175f29d0123d64ad5b4aa4a5ba5770315e4b00e10dd806946695bbdadc306af0083bb620afe6
7
- data.tar.gz: 0d366788a6163b62f6c5e1b9e9d7a27ffc46898efb93067acc5f5b1fee675452395e5ad0671b6218344cd318dbf3a2b428fcb4479c9fb2377e9db5c2030bc261
6
+ metadata.gz: 7f66b0f45e6f851e83e6d27872a13e3a84689b5a89c80ec5dd33bd4ad685f5fabbe12cb6f44f65e0ceb749f995d4b0295e310b455fcf9897538b971b95dcd135
7
+ data.tar.gz: fc0b33a4f407cc54bc52602d16ca62d4a098b1177f5f993f5e52672253c9031b489215ea1fbf3ae8c48cf21139f010f4692baa94ecb52118e9ca25c117e8ec71
data/README.md CHANGED
@@ -40,6 +40,9 @@ require 'pdf_forms'
40
40
  # add :data_format => 'XFdf' option to generate XFDF instead of FDF when
41
41
  # filling a form (XFDF is supposed to have better support for non-western
42
42
  # encodings)
43
+ # add :data_format => 'FdfHex' option to generate FDF with values passed in
44
+ # UTF16 hexadecimal format (Hexadecimal format has also proven more reliable
45
+ # for passing latin accented characters to pdftk)
43
46
  # add :utf8_fields => true in order to get UTF8 encoded field metadata (this
44
47
  # will use dump_data_fields_utf8 instead of dump_data_fields in the call to
45
48
  # pdftk)
@@ -5,6 +5,7 @@ require 'pdf_forms/normalize_path'
5
5
  require 'pdf_forms/data_format'
6
6
  require 'pdf_forms/fdf'
7
7
  require 'pdf_forms/xfdf'
8
+ require 'pdf_forms/fdf_hex'
8
9
  require 'pdf_forms/pdf'
9
10
  require 'pdf_forms/pdftk_wrapper'
10
11
 
@@ -0,0 +1,39 @@
1
+ # coding: UTF-8
2
+
3
+ module PdfForms
4
+ # Map keys and values to Adobe's FDF format.
5
+ #
6
+ # This is a variation of the original Fdf data format, values are encoded in UTF16 hexadesimal
7
+ # notation to improve compatibility with non ascii charsets.
8
+ #
9
+ # Information about hexadesimal FDF values was found here:
10
+ #
11
+ # http://stackoverflow.com/questions/6047970/weird-characters-when-filling-pdf-with-pdftk
12
+ #
13
+ class FdfHex < Fdf
14
+ private
15
+
16
+ def field(key, value)
17
+ "<</T(#{key})/V" +
18
+ (Array === value ? encode_many(value) : encode_value_as_hex(value)) +
19
+ ">>\n"
20
+ end
21
+
22
+ def encode_many(values)
23
+ "[#{values.map { |v| encode_value_as_hex(v) }.join}]"
24
+ end
25
+
26
+ def encode_value_as_hex(value)
27
+ value = value.to_s
28
+ utf_16 = value.encode('UTF-16BE', :invalid => :replace, :undef => :replace)
29
+ hex = utf_16.unpack('H*').first
30
+ hex.force_encoding 'ASCII-8BIT' # jruby
31
+ '<FEFF' + hex.upcase + '>'
32
+ end
33
+
34
+ # Fdf implementation encodes to ISO-8859-15 which we do not want here.
35
+ def encode_data(fdf)
36
+ fdf
37
+ end
38
+ end
39
+ end
@@ -160,11 +160,11 @@ module PdfForms
160
160
  when String
161
161
  pdftk = first_arg
162
162
  options = args.shift || {}
163
- raise InvalidArgumentError.new("expected hash, got #{options.class.name}") unless Hash === options
163
+ raise ArgumentError.new("expected hash, got #{options.class.name}") unless Hash === options
164
164
  when Hash
165
165
  options = first_arg
166
166
  else
167
- raise InvalidArgumentError.new("expected string or hash, got #{first_arg.class.name}")
167
+ raise ArgumentError.new("expected string or hash, got #{first_arg.class.name}")
168
168
  end
169
169
  end
170
170
  [pdftk, options]
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module PdfForms
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Krämer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cliver
@@ -86,6 +86,7 @@ files:
86
86
  - lib/pdf_forms.rb
87
87
  - lib/pdf_forms/data_format.rb
88
88
  - lib/pdf_forms/fdf.rb
89
+ - lib/pdf_forms/fdf_hex.rb
89
90
  - lib/pdf_forms/field.rb
90
91
  - lib/pdf_forms/normalize_path.rb
91
92
  - lib/pdf_forms/pdf.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: 1.3.6
113
114
  requirements: []
114
115
  rubyforge_project: pdf-forms
115
- rubygems_version: 2.5.1
116
+ rubygems_version: 2.7.6
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: Fill out PDF forms with pdftk (http://www.accesspdf.com/pdftk/).