pdf_ravager 0.0.5-java → 0.0.6-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -4
- data/lib/pdf_ravager/pdf.rb +11 -7
- data/lib/pdf_ravager/ravager.rb +2 -2
- data/lib/pdf_ravager/version.rb +1 -1
- data/spec/pdf_spec.rb +4 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -17,7 +17,7 @@ data = {:name => 'Bob', :gender => 'm', :relation => 'Uncle' }
|
|
17
17
|
|
18
18
|
info = pdf do
|
19
19
|
text 'name', data[:name]
|
20
|
-
|
20
|
+
text 'name_stylized', "<b>#{data[:name]}</b>", :rich => true
|
21
21
|
radio_group 'sex' do
|
22
22
|
fill 'male' if data[:gender] == 'm'
|
23
23
|
fill 'female' if data[:gender] == 'f'
|
@@ -45,14 +45,18 @@ To query and modify a form's field names, use a tool such as Adobe
|
|
45
45
|
LiveCycle.
|
46
46
|
|
47
47
|
### Rich Text
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
Rich text is specific to XFA forms. To understand how it should be used,
|
49
|
+
see the "Rich Text Reference" section of [Adobe's XFA standard][1].
|
50
|
+
Rich Text is defined there as a subset of
|
51
51
|
XHTML and CSS which uses some custom restrictions and extensions by
|
52
52
|
Adobe. The minimum XHTML and CSS elements that a standards-compliant
|
53
53
|
XFA processor (e.g. Adobe Reader) must support are also listed there
|
54
54
|
and can be used as a guide.
|
55
55
|
|
56
|
+
**Note**: Rich text values are not HTML-escaped or sanitized in any
|
57
|
+
way. It is suggested that you call `CGI.escape_html` on user-supplied
|
58
|
+
input.
|
59
|
+
|
56
60
|
### Checkbox Groups
|
57
61
|
Because there is no such thing as a "checkbox group," the
|
58
62
|
`checkbox_group` syntax is simply syntactic sugar for calling
|
data/lib/pdf_ravager/pdf.rb
CHANGED
@@ -11,11 +11,11 @@ module PDFRavager
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def text(name, value, opts={})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
if opts.empty?
|
15
|
+
@fields << {:name => name, :value => value, :type => :text}
|
16
|
+
else
|
17
|
+
@fields << {:name => name, :value => value, :type => :text, :options => opts}
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def check(name, opts={})
|
@@ -59,7 +59,7 @@ module PDFRavager
|
|
59
59
|
else
|
60
60
|
f[:value]
|
61
61
|
end
|
62
|
-
pdf.set_field_value(f[:name], value, f[:type])
|
62
|
+
pdf.set_field_value(f[:name], value, f[:type], f[:options])
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -82,9 +82,13 @@ module PDFRavager
|
|
82
82
|
|
83
83
|
def self.json_create(obj)
|
84
84
|
fields = obj["data"]["fields"].map do |f|
|
85
|
-
# symbolize the keys
|
85
|
+
# symbolize the root keys
|
86
86
|
f = f.inject({}){|h,(k,v)| h[k.to_sym] = v; h}
|
87
87
|
f[:type] = f[:type].to_sym if f[:type]
|
88
|
+
# symbolize the :options keys
|
89
|
+
if f[:options]
|
90
|
+
f[:options] = f[:options].inject({}){|h,(k,v)| h[k.to_sym] = v; h}
|
91
|
+
end
|
88
92
|
f
|
89
93
|
end
|
90
94
|
o = new(obj["data"]["name"], :fields => fields)
|
data/lib/pdf_ravager/ravager.rb
CHANGED
@@ -31,8 +31,8 @@ module PDFRavager
|
|
31
31
|
out
|
32
32
|
end
|
33
33
|
|
34
|
-
def set_field_value(name, value, type=nil)
|
35
|
-
return set_rich_text_field(name, value) if type == :
|
34
|
+
def set_field_value(name, value, type=nil, options={})
|
35
|
+
return set_rich_text_field(name, value) if type == :text && options[:rich] == true
|
36
36
|
begin
|
37
37
|
# First try AcroForms method of setting value
|
38
38
|
@afields.setField(XfaForm::Xml2Som::getShortName(SOM.escape(name)), value)
|
data/lib/pdf_ravager/version.rb
CHANGED
data/spec/pdf_spec.rb
CHANGED
@@ -4,9 +4,9 @@ require 'pdf_ravager/pdf'
|
|
4
4
|
class TestPDF < MiniTest::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@pdf = pdf 'foo.pdf' do
|
7
|
-
text
|
8
|
-
|
9
|
-
check
|
7
|
+
text 'text', 'foo'
|
8
|
+
text 'rich_text', '<b>foo</b>', :rich => true
|
9
|
+
check 'checkbox'
|
10
10
|
checkbox_group 'checkbox_group' do
|
11
11
|
check 'foo'
|
12
12
|
end
|
@@ -27,7 +27,7 @@ class TestPDF < MiniTest::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_that_rich_text_is_set
|
30
|
-
assert_includes @pdf.fields, {:name => 'rich_text', :value => '<b>foo</b>', :type => :
|
30
|
+
assert_includes @pdf.fields, {:name => 'rich_text', :value => '<b>foo</b>', :type => :text, :options => {:rich => true}}
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_that_checkbox_is_set
|