itext-jruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/itext-jruby.gemspec +2 -2
  3. data/lib/itext.rb +12 -2
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "itext-jruby"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ernest Bursa"]
12
- s.date = "2013-09-04"
12
+ s.date = "2013-09-05"
13
13
  s.description = "IText"
14
14
  s.email = "ernest@bzdury.pl"
15
15
  s.extra_rdoc_files = [
@@ -21,10 +21,15 @@ class Itext
21
21
 
22
22
  def save(save_to = nil)
23
23
  save_to ||= @path
24
- raise ArgumentError.new('Specified file does not exists') unless File.exists?(@path)
24
+
25
+ output_file = if File.exists?(@path)
26
+ Tempfile.new(['temp_pdf', '.pdf'])
27
+ else
28
+ File.open(save_to, "r+")
29
+ end
25
30
 
26
31
  @reader = Java::ComLowagieTextPdf::PdfReader.new(@path.to_java(:string))
27
- @buffer = Java::JavaIo::FileOutputStream.new save_to
32
+ @buffer = Java::JavaIo::FileOutputStream.new output_file.path
28
33
  @stamper = Java::ComLowagieTextPdf::PdfStamper.new @reader, @buffer
29
34
 
30
35
  # Run all attached hooks
@@ -32,6 +37,11 @@ class Itext
32
37
 
33
38
  @stamper.close
34
39
 
40
+ if output_file.is_a?(Tempfile)
41
+ FileUtils.rm(save_to) if File.exists?(save_to)
42
+ FileUtils.cp(output_file.path, save_to)
43
+ end
44
+
35
45
  # Return output path
36
46
  save_to
37
47
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: itext-jruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ernest Bursa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-04 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda