pdf-forms 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pdf_forms/field.rb +25 -0
- data/lib/pdf_forms/pdf.rb +10 -4
- data/lib/pdf_forms/pdftk_wrapper.rb +5 -1
- data/lib/pdf_forms/version.rb +1 -1
- metadata +3 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
module PdfForms
|
2
|
+
class Field
|
3
|
+
|
4
|
+
# FieldType: Button
|
5
|
+
# FieldName: Sprachoptionen_Inverssuche_Widerspruch
|
6
|
+
# FieldFlags: 0
|
7
|
+
# FieldJustification: Left
|
8
|
+
# FieldStateOption: Ja
|
9
|
+
# FieldStateOption: Off
|
10
|
+
def initialize(field_description)
|
11
|
+
field_description.each_line do |line|
|
12
|
+
case line
|
13
|
+
when /FieldType:\s*(.+?)\s*$/
|
14
|
+
@type = $1
|
15
|
+
when /FieldName:\s*(.+?)\s*$/
|
16
|
+
@name = $1
|
17
|
+
when /FieldStateOption:\s*(.+?)\s*$/
|
18
|
+
(@options ||= []) << $1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :name, :type, :options
|
24
|
+
end
|
25
|
+
end
|
data/lib/pdf_forms/pdf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pdf_forms/field'
|
2
|
+
|
1
3
|
module PdfForms
|
2
4
|
class Pdf
|
3
5
|
|
@@ -11,19 +13,23 @@ module PdfForms
|
|
11
13
|
@pdftk = pdftk
|
12
14
|
end
|
13
15
|
|
16
|
+
# list of field objects for all defined fields
|
14
17
|
def fields
|
15
18
|
@fields ||= read_fields
|
16
19
|
end
|
17
20
|
|
21
|
+
# the field object for the named field
|
22
|
+
def field(name)
|
23
|
+
fields.detect{ |f| f.name == name }
|
24
|
+
end
|
25
|
+
|
18
26
|
protected
|
19
27
|
|
20
28
|
def read_fields
|
21
29
|
field_output = @pdftk.call_pdftk quote_path(path), 'dump_data_fields'
|
22
30
|
@fields = field_output.split(/^---\n/).map do |field_text|
|
23
|
-
if field_text =~
|
24
|
-
|
25
|
-
end
|
26
|
-
end.compact.uniq
|
31
|
+
Field.new field_text if field_text =~ /FieldName:/
|
32
|
+
end.compact
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -47,10 +47,14 @@ module PdfForms
|
|
47
47
|
Pdf.new path, self
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def get_fields(template)
|
51
51
|
read(template).fields
|
52
52
|
end
|
53
53
|
|
54
|
+
def get_field_names(template)
|
55
|
+
read(template).fields.map{|f| f.name}
|
56
|
+
end
|
57
|
+
|
54
58
|
def call_pdftk(*args)
|
55
59
|
%x{#{pdftk_command args}}
|
56
60
|
end
|
data/lib/pdf_forms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -51,6 +51,7 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- lib/pdf_forms/fdf.rb
|
54
|
+
- lib/pdf_forms/field.rb
|
54
55
|
- lib/pdf_forms/pdf.rb
|
55
56
|
- lib/pdf_forms/pdftk_wrapper.rb
|
56
57
|
- lib/pdf_forms/safe_path.rb
|