tv-pdf-stamper 0.3.8 → 0.3.9

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.
@@ -10,8 +10,6 @@ include FileUtils
10
10
 
11
11
  module PDF
12
12
  class Stamper
13
- VERSION = "0.3.6"
14
-
15
13
  if RUBY_PLATFORM =~ /java/ # ifdef to check if your using JRuby
16
14
  require 'pdf/stamper/jruby'
17
15
  else
@@ -35,7 +33,7 @@ module PDF
35
33
  # pdf.image :photo, "photo.jpg"
36
34
  # pdf.checkbox :hungry
37
35
  # pdf.save_as "my_output"
38
-
36
+
39
37
  # Set a textfield defined by key and text to value.
40
38
  def text(key, value)
41
39
  @form.setField(key.to_s, value.to_s) # Value must be a string or itext will error.
@@ -48,11 +46,11 @@ module PDF
48
46
 
49
47
  all_states = @form.getAppearanceStates(key.to_s)
50
48
  yes_state = all_states.reject{|x| x == "Off"}
51
-
52
-
49
+
50
+
53
51
  @form.setField(key.to_s, yes_state.first) unless (yes_state.size == 0)
54
52
  end
55
-
53
+
56
54
  # Get checkbox values
57
55
  def get_checkbox_values(key)
58
56
  field_type = @form.getFieldType(key.to_s)
@@ -75,25 +73,24 @@ module PDF
75
73
  update_canvas_list(page)
76
74
  @canvas_list[page].rectangle(x, y, width, height)
77
75
  end
78
-
76
+
79
77
  # Saves the PDF into a file defined by path given.
80
- def save_as(file)
81
- File.open(file, "wb") { |f| f.write to_s }
78
+ def save_as(file, flatten_form=true)
79
+ File.open(file, "wb") { |f| f.write to_s(flatten_form) }
82
80
  end
83
-
81
+
84
82
  private
85
-
83
+
86
84
  def update_canvas_list(page)
87
85
  @canvas_list[page] = @stamp.getOverContent(page) unless @canvas_list.has_key?(page)
88
86
  end
89
87
 
90
- def fill
88
+ def fill(flatten_form=true)
91
89
  @canvas_list.values.each do |c|
92
90
  c.stroke
93
91
  end
94
- @stamp.setFormFlattening(true)
92
+ @stamp.setFormFlattening(flatten_form)
95
93
  @stamp.close
96
94
  end
97
95
  end
98
96
  end
99
-
@@ -25,12 +25,10 @@ module PDF
25
25
  end
26
26
 
27
27
  def template(template)
28
- # NOTE I'd rather use a ByteArrayOutputStream. However I
29
- # couldn't get it working. Patches welcome.
30
28
  #@tmp_path = File.join(Dir::tmpdir, 'pdf-stamper-' + rand(10000).to_s + '.pdf')
31
29
  reader = PdfReader.new(template)
32
30
  @baos = ByteArrayOutputStream.new
33
- @stamp = PdfStamper.new(reader, @baos)#FileOutputStream.new(@tmp_path))
31
+ @stamp = PdfStamper.new(reader, @baos)
34
32
  @form = @stamp.getAcroFields()
35
33
  @black = GrayColor.new(0.0)
36
34
  @canvas_list = { 1 => @stamp.getOverContent(1) }
@@ -60,8 +58,8 @@ module PDF
60
58
 
61
59
  # Takes the PDF output and sends as a string. Basically it's sole
62
60
  # purpose is to be used with send_data in rails.
63
- def to_s
64
- fill
61
+ def to_s(flatten_form=true)
62
+ fill(flatten_form)
65
63
  String.from_java_bytes(@baos.toByteArray)
66
64
  end
67
65
  end
@@ -0,0 +1,5 @@
1
+ module PDF
2
+ class Stamper
3
+ VERSION = "0.3.9"
4
+ end
5
+ end
@@ -1,8 +1,11 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
4
+ require 'pdf/stamper/version'
5
+
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{tv-pdf-stamper}
5
- s.version = "0.3.8"
8
+ s.version = PDF::Stamper::VERSION
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Paul Schreiber", "Wes Morgan"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tv-pdf-stamper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -69,6 +69,7 @@ files:
69
69
  - lib/pdf/stamper.rb
70
70
  - lib/pdf/stamper/jruby.rb
71
71
  - lib/pdf/stamper/rjb.rb
72
+ - lib/pdf/stamper/version.rb
72
73
  - pdf-stamper.gemspec
73
74
  - spec/example.rb
74
75
  - spec/logo.gif