pdf-merger 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 0.3.0 2012-08-22
2
+ * instead of failing completely, merge the valid files and return an array of missing and invalid PDFs
3
+
1
4
  == 0.2.0 2012-04-26
2
5
  * add_javascript adds JavaScript to the new file
3
6
 
data/README.txt CHANGED
@@ -7,11 +7,12 @@ Merge PDFs using iText.
7
7
  == Example
8
8
 
9
9
  require "pdf/merger"
10
+ failure_list = []
10
11
  pdf = PDF::Merger.new
11
12
  pdf.add_file "foo.pdf"
12
13
  pdf.add_file "bar.pdf"
13
14
  pdf.add_javascript "this.print(true);"
14
- pdf.save_as "combined.pdf"
15
+ pdf.save_as "combined.pdf", failure_list
15
16
 
16
17
  == Encoding
17
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -10,7 +10,7 @@ include FileUtils
10
10
 
11
11
  module PDF
12
12
  class Merger
13
- VERSION = "0.1.2"
13
+ VERSION = "0.3.0"
14
14
 
15
15
  if RUBY_PLATFORM =~ /java/ # ifdef to check if your using JRuby
16
16
  require 'pdf/merger/jruby'
@@ -14,19 +14,33 @@ module PDF
14
14
  class Merger
15
15
 
16
16
  # Saves the PDF into a file defined by path given.
17
- # return the number of pages in the new file
18
- def save_as(output_file_path)
17
+ # - return the number of pages in the new file
18
+ # - populate failure_list with paths of missing or invalid PDFs
19
+ def save_as(output_file_path, failure_list=[])
19
20
  filestream = FileOutputStream.new(output_file_path)
20
21
  copy = PdfCopyFields.new(filestream)
21
22
 
22
23
  @files_to_merge.each do |f|
23
- copy.addDocument(PdfReader.new(f))
24
+ if File.exists?(f)
25
+ begin
26
+ copy.addDocument(PdfReader.new(f))
27
+ rescue => e
28
+ failure_list << f
29
+ Rails.logger.warn "PDF::Merger: Invalid PDF: #{f}"
30
+ end
31
+ else
32
+ failure_list << f
33
+ Rails.logger.warn "PDF::Merger: File does not exist: #{f}"
34
+ end
24
35
  end
25
-
26
- copy.addJavaScript(@js) if @js.present?
27
36
 
28
- copy.close()
29
- PdfReader.new(output_file_path).getNumberOfPages
37
+ if @files_to_merge.size - failure_list.size > 0
38
+ copy.addJavaScript(@js) if @js.present?
39
+ copy.close()
40
+ PdfReader.new(output_file_path).getNumberOfPages
41
+ else
42
+ 0
43
+ end
30
44
  end
31
45
 
32
46
  end
@@ -18,9 +18,11 @@ module PDF
18
18
  #
19
19
  # Check the RJB documentation if you are having issues with this.
20
20
  class Merger
21
+
21
22
  # Saves the PDF into a file defined by path given.
22
- # return the number of pages in the new file
23
- def save_as(output_file_path)
23
+ # - return the number of pages in the new file
24
+ # - populate failure_list with paths of missing or invalid PDFs
25
+ def save_as(output_file_path, failure_list=[])
24
26
  @pdfreader = Rjb::import('com.lowagie.text.pdf.PdfReader')
25
27
  @pdfcopyfields = Rjb::import('com.lowagie.text.pdf.PdfCopyFields')
26
28
  @filestream = Rjb::import('java.io.FileOutputStream')
@@ -29,13 +31,26 @@ module PDF
29
31
  copy = @pdfcopyfields.new(filestream)
30
32
 
31
33
  @files_to_merge.each do |f|
32
- copy.addDocument(@pdfreader.new(f))
34
+ if File.exists?(f)
35
+ begin
36
+ copy.addDocument(@pdfreader.new(f))
37
+ rescue => e
38
+ failure_list << f
39
+ Rails.logger.warn "PDF::Merger: Invalid PDF: #{f}"
40
+ end
41
+ else
42
+ failure_list << f
43
+ Rails.logger.warn "PDF::Merger: File does not exist: #{f}"
44
+ end
33
45
  end
34
46
 
35
- copy.addJavaScript(@js) if @js.present?
36
-
37
- copy.close()
38
- @pdfreader.new(output_file_path).getNumberOfPages
47
+ if @files_to_merge.size - failure_list.size > 0
48
+ copy.addJavaScript(@js) if @js.present?
49
+ copy.close()
50
+ @pdfreader.new(output_file_path).getNumberOfPages
51
+ else
52
+ 0
53
+ end
39
54
  end
40
55
 
41
56
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pdf-merger"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Schreiber"]
12
- s.date = "2012-04-26"
12
+ s.date = "2012-08-22"
13
13
  s.description = "Merge multiple PDFs in to one using iText's PdfCopyFile."
14
14
  s.email = "paulschreiber@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = "http://github.com/paulschreiber/pdf-merger"
36
36
  s.licenses = ["MIT"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.15"
38
+ s.rubygems_version = "1.8.23"
39
39
  s.summary = "Merge PDFs."
40
40
 
41
41
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,92 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pdf-merger
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Paul Schreiber
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
30
15
  name: shoulda
31
- version_requirements: *id001
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
23
  prerelease: false
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
36
33
  none: false
37
- requirements:
34
+ requirements:
38
35
  - - ~>
39
- - !ruby/object:Gem::Version
40
- hash: 23
41
- segments:
42
- - 1
43
- - 0
44
- - 0
36
+ - !ruby/object:Gem::Version
45
37
  version: 1.0.0
46
- name: bundler
47
- version_requirements: *id002
48
38
  type: :development
49
39
  prerelease: false
50
- - !ruby/object:Gem::Dependency
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
42
+ requirements:
54
43
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 7
57
- segments:
58
- - 1
59
- - 6
60
- - 4
61
- version: 1.6.4
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
62
47
  name: jeweler
63
- version_requirements: *id003
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.6.4
64
54
  type: :development
65
55
  prerelease: false
66
- - !ruby/object:Gem::Dependency
67
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
68
57
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.4
62
+ - !ruby/object:Gem::Dependency
76
63
  name: rcov
77
- version_requirements: *id004
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
78
70
  type: :development
79
71
  prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
80
78
  description: Merge multiple PDFs in to one using iText's PdfCopyFile.
81
79
  email: paulschreiber@gmail.com
82
80
  executables: []
83
-
84
81
  extensions: []
85
-
86
- extra_rdoc_files:
82
+ extra_rdoc_files:
87
83
  - LICENSE.txt
88
84
  - README.txt
89
- files:
85
+ files:
90
86
  - Gemfile
91
87
  - Gemfile.lock
92
88
  - History.txt
@@ -102,37 +98,31 @@ files:
102
98
  - spec/pdf_merger_spec.rb
103
99
  - spec/test_template.pdf
104
100
  homepage: http://github.com/paulschreiber/pdf-merger
105
- licenses:
101
+ licenses:
106
102
  - MIT
107
103
  post_install_message:
108
104
  rdoc_options: []
109
-
110
- require_paths:
105
+ require_paths:
111
106
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
107
+ required_ruby_version: !ruby/object:Gem::Requirement
113
108
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
119
114
  - 0
120
- version: "0"
121
- required_rubygems_version: !ruby/object:Gem::Requirement
115
+ hash: 3756396917728053956
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
117
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3
127
- segments:
128
- - 0
129
- version: "0"
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
130
122
  requirements: []
131
-
132
123
  rubyforge_project:
133
- rubygems_version: 1.8.15
124
+ rubygems_version: 1.8.23
134
125
  signing_key:
135
126
  specification_version: 3
136
127
  summary: Merge PDFs.
137
128
  test_files: []
138
-