pdf-merger 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cb87a85e86eef440732b4f573a6f725132f8790
4
+ data.tar.gz: 4b7a7d793aa6fe8f376e24faecac7d60718371de
5
+ SHA512:
6
+ metadata.gz: 51726ff5348586f7fcc74bd43695956e7e1970ba14ac559c469528f47fa9c7be992096e0d2c21285c5bca2f7f596d47dc2769857cf098860481c9039ec5f5eb7
7
+ data.tar.gz: 92a9853c0f5a3fc67aeee41e8bb090ffe3e3981902fc219db6bea33ef331c22436b92fae935c353cefece842c30a306934ff5fa0c1dc126e6bf5355de4a3ea6e
@@ -0,0 +1,46 @@
1
+ ### Carrierwave
2
+
3
+ Information from @SicutDominus
4
+
5
+ [Carrierwave gem](https://github.com/carrierwaveuploader/carrierwave).
6
+
7
+ By default Carrierwave uploads files into `/public/uploads`. Here is an example to merge all attachments on a standard `user` model into a single `report` file, stored in `/tmp`.
8
+
9
+ #models/user.rb
10
+ class User < ActiveRecord::Base
11
+ has_many :attachments, dependent: :destroy
12
+ accepts_nested_attributes_for :attachments, :allow_destroy => true
13
+ end
14
+
15
+ #config/routes.rb
16
+ get 'users/:id/report' => 'users#report', as: :users_report
17
+
18
+ #views/users/show.html.erb
19
+ <%= link_to 'Report', users_report_path(@user) %>
20
+
21
+ #app/controllers/users_controller.rb
22
+ def report
23
+ failure_list = []
24
+ pdf = PDF::Merger.new
25
+
26
+ if @user.attachments.empty?
27
+ flash[:error] = 'No attachments.'
28
+ else
29
+ for attachment in @user.attachments
30
+ # Note the .to_s, otherwise code fails by passing a Ruby item rather than string into add_file
31
+ pdf.add_file Rails.root.join("public#{attachment.file.to_s}").to_s
32
+ end
33
+
34
+ # Best to have some kind of unique identifier in the file name so they aren't constantly overwriting each other
35
+ save_path = Rails.root.join('tmp', "report - #{@user.email}.pdf").to_s
36
+ pdf.save_as(save_path, failure_list)
37
+ # File now stored in tmp
38
+ # Manipulate the file here (eg. send out via email), then uncomment the line below if you want it deleted.
39
+ # Comment the line below to examine file for testing purposes
40
+ #File.delete(save_path)
41
+
42
+ flash[:notice] = 'Report successfully generated.'
43
+ end
44
+
45
+ redirect_to @user
46
+ end
data/Gemfile CHANGED
@@ -9,5 +9,4 @@ group :development do
9
9
  gem "shoulda"
10
10
  gem "bundler"
11
11
  gem "jeweler"
12
- gem "rcov"
13
12
  end
@@ -1,20 +1,70 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- git (1.2.5)
5
- jeweler (1.8.4)
6
- bundler (~> 1.0)
4
+ activesupport (4.1.5)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ descendants_tracker (0.0.4)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ faraday (0.9.0)
15
+ multipart-post (>= 1.2, < 3)
16
+ git (1.2.8)
17
+ github_api (0.12.1)
18
+ addressable (~> 2.3)
19
+ descendants_tracker (~> 0.0.4)
20
+ faraday (~> 0.8, < 0.10)
21
+ hashie (>= 3.2)
22
+ multi_json (>= 1.7.5, < 2.0)
23
+ nokogiri (~> 1.6.3)
24
+ oauth2
25
+ hashie (3.3.1)
26
+ highline (1.6.21)
27
+ i18n (0.6.11)
28
+ jeweler (2.0.1)
29
+ builder
30
+ bundler (>= 1.0)
7
31
  git (>= 1.2.5)
32
+ github_api
33
+ highline (>= 1.6.15)
34
+ nokogiri (>= 1.5.10)
8
35
  rake
9
36
  rdoc
10
- json (1.7.5)
11
- json (1.7.5-java)
12
- rake (0.9.2.2)
13
- rcov (0.9.10)
14
- rcov (0.9.10-java)
15
- rdoc (3.12)
37
+ json (1.8.1)
38
+ json (1.8.1-java)
39
+ jwt (1.0.0)
40
+ mini_portile (0.6.0)
41
+ minitest (5.4.1)
42
+ multi_json (1.10.1)
43
+ multi_xml (0.5.5)
44
+ multipart-post (2.0.0)
45
+ nokogiri (1.6.3.1)
46
+ mini_portile (= 0.6.0)
47
+ nokogiri (1.6.3.1-java)
48
+ oauth2 (1.0.0)
49
+ faraday (>= 0.8, < 0.10)
50
+ jwt (~> 1.0)
51
+ multi_json (~> 1.3)
52
+ multi_xml (~> 0.5)
53
+ rack (~> 1.2)
54
+ rack (1.5.2)
55
+ rake (10.3.2)
56
+ rdoc (4.1.1)
16
57
  json (~> 1.4)
17
- shoulda (2.11.3)
58
+ shoulda (3.5.0)
59
+ shoulda-context (~> 1.0, >= 1.0.1)
60
+ shoulda-matchers (>= 1.4.1, < 3.0)
61
+ shoulda-context (1.2.1)
62
+ shoulda-matchers (2.6.2)
63
+ activesupport (>= 3.0.0)
64
+ thread_safe (0.3.4)
65
+ thread_safe (0.3.4-java)
66
+ tzinfo (1.2.2)
67
+ thread_safe (~> 0.1)
18
68
 
19
69
  PLATFORMS
20
70
  java
@@ -23,5 +73,4 @@ PLATFORMS
23
73
  DEPENDENCIES
24
74
  bundler
25
75
  jeweler
26
- rcov
27
76
  shoulda
@@ -1,3 +1,7 @@
1
+ == 0.3.2 2014-08-30
2
+ * updated gems/dependencies for Ruby 1.9+
3
+ * documentation updated
4
+
1
5
  == 0.3.1 2012-10-25
2
6
  * use java_import instead of include_class (include_class deprecated in jruby 1.7.0)
3
7
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Paul Schreiber
1
+ Copyright (c) 2010-2014 Paul Schreiber
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,43 @@
1
+ # PDF Merging (pdf/merger)
2
+ by Paul Schreiber
3
+
4
+ [Github repo](http://github.com/paulschreiber/pdf-merger/)
5
+
6
+ Merge PDFs using iText.
7
+
8
+ ## Ruby
9
+
10
+ require "pdf/merger"
11
+ failure_list = []
12
+ pdf = PDF::Merger.new
13
+ pdf.add_file "foo.pdf"
14
+ pdf.add_file "bar.pdf"
15
+ pdf.add_javascript "this.print(true);"
16
+ pdf.save_as "combined.pdf", failure_list
17
+
18
+ ## Rails
19
+
20
+ ### Installation
21
+
22
+ # Gemfile.rb
23
+ gem 'rjb'
24
+ gem 'pdf-merger'
25
+
26
+ As always:
27
+
28
+ $ bundle install
29
+ $ rails server
30
+
31
+ ## Encoding
32
+
33
+ On some systems, such as Linux, you need to manually set the encoding. If you don't do that, merging on filenames with special characters will fail with a java.io.IOEXception (not found as file or resource).
34
+
35
+ I added this line to my `environments/production.rb` to fix the problem:
36
+
37
+ # environments/production.rb
38
+ ENV["LC_ALL"] = "en_US.utf8"
39
+
40
+ ## License
41
+
42
+ Copyright 2010-14 Paul Schreiber. Released under the MIT License.
43
+ See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -32,17 +32,9 @@ Rake::TestTask.new(:test) do |test|
32
32
  test.verbose = true
33
33
  end
34
34
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
41
- end
42
-
43
35
  task :default => :test
44
36
 
45
- require 'rake/rdoctask'
37
+ require 'rdoc/task'
46
38
  Rake::RDocTask.new do |rdoc|
47
39
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
40
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -10,8 +10,8 @@ include FileUtils
10
10
 
11
11
  module PDF
12
12
  class Merger
13
- VERSION = "0.3.1"
14
-
13
+ VERSION = "0.3.2"
14
+
15
15
  if RUBY_PLATFORM =~ /java/ # ifdef to check if your using JRuby
16
16
  require 'pdf/merger/jruby'
17
17
  else
@@ -26,20 +26,28 @@ module PDF
26
26
  # pdf.add_file "foo.pdf"
27
27
  # pdf.add_file "bar.pdf"
28
28
  # pdf.save_as "combined.pdf"
29
-
29
+
30
30
  def initialize
31
31
  @files_to_merge = []
32
32
  @js = nil
33
33
  end
34
-
34
+
35
35
  def add_javascript(js)
36
36
  @js = js
37
37
  end
38
-
38
+
39
39
  def add_file(file_path)
40
40
  @files_to_merge << file_path
41
41
  end
42
-
42
+
43
+ def log(message)
44
+ if defined? Rails
45
+ Rails.logger.warn message
46
+ else
47
+ puts message
48
+ end
49
+ end
50
+
43
51
  end
44
52
  end
45
-
53
+
@@ -1,6 +1,6 @@
1
1
  # = pdf/merger/rjb.rb -- PDF template stamping.
2
2
  #
3
- # Copyright 2010-12 Paul Schreiber
3
+ # Copyright 2010-14 Paul Schreiber
4
4
 
5
5
  $:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'ext'))
6
6
  require 'java'
@@ -19,29 +19,29 @@ module PDF
19
19
  def save_as(output_file_path, failure_list=[])
20
20
  filestream = FileOutputStream.new(output_file_path)
21
21
  copy = PdfCopyFields.new(filestream)
22
-
22
+
23
23
  @files_to_merge.each do |f|
24
24
  if File.exists?(f)
25
25
  begin
26
26
  copy.addDocument(PdfReader.new(f))
27
27
  rescue => e
28
28
  failure_list << f
29
- Rails.logger.warn "PDF::Merger: Invalid PDF: #{f}"
29
+ log "PDF::Merger: Invalid PDF: #{f}"
30
30
  end
31
31
  else
32
32
  failure_list << f
33
- Rails.logger.warn "PDF::Merger: File does not exist: #{f}"
33
+ log "PDF::Merger: File does not exist: #{f}"
34
34
  end
35
35
  end
36
-
36
+
37
37
  if @files_to_merge.size - failure_list.size > 0
38
- copy.addJavaScript(@js) if @js.present?
38
+ copy.addJavaScript(@js) if @js && !@js.empty?
39
39
  copy.close()
40
40
  PdfReader.new(output_file_path).getNumberOfPages
41
41
  else
42
42
  0
43
43
  end
44
44
  end
45
-
45
+
46
46
  end
47
47
  end
@@ -36,16 +36,16 @@ module PDF
36
36
  copy.addDocument(@pdfreader.new(f))
37
37
  rescue => e
38
38
  failure_list << f
39
- Rails.logger.warn "PDF::Merger: Invalid PDF: #{f}"
39
+ log "PDF::Merger: Invalid PDF: #{f}"
40
40
  end
41
41
  else
42
42
  failure_list << f
43
- Rails.logger.warn "PDF::Merger: File does not exist: #{f}"
43
+ log "PDF::Merger: File does not exist: #{f}"
44
44
  end
45
45
  end
46
46
 
47
47
  if @files_to_merge.size - failure_list.size > 0
48
- copy.addJavaScript(@js) if @js.present?
48
+ copy.addJavaScript(@js) if @js && !@js.empty?
49
49
  copy.close()
50
50
  @pdfreader.new(output_file_path).getNumberOfPages
51
51
  else
@@ -2,26 +2,29 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: pdf-merger 0.3.2 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "pdf-merger"
8
- s.version = "0.3.1"
9
+ s.version = "0.3.2"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Paul Schreiber"]
12
- s.date = "2012-10-25"
14
+ s.date = "2014-08-30"
13
15
  s.description = "Merge multiple PDFs in to one using iText's PdfCopyFile."
14
16
  s.email = "paulschreiber@gmail.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
- "README.txt"
19
+ "README.md"
18
20
  ]
19
21
  s.files = [
22
+ "Carrierwave.md",
20
23
  "Gemfile",
21
24
  "Gemfile.lock",
22
25
  "History.txt",
23
26
  "LICENSE.txt",
24
- "README.txt",
27
+ "README.md",
25
28
  "Rakefile",
26
29
  "VERSION",
27
30
  "ext/iText-4.2.0.jar",
@@ -34,29 +37,25 @@ Gem::Specification.new do |s|
34
37
  ]
35
38
  s.homepage = "http://github.com/paulschreiber/pdf-merger"
36
39
  s.licenses = ["MIT"]
37
- s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.24"
40
+ s.rubygems_version = "2.2.0"
39
41
  s.summary = "Merge PDFs."
40
42
 
41
43
  if s.respond_to? :specification_version then
42
- s.specification_version = 3
44
+ s.specification_version = 4
43
45
 
44
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
47
  s.add_development_dependency(%q<shoulda>, [">= 0"])
46
48
  s.add_development_dependency(%q<bundler>, [">= 0"])
47
49
  s.add_development_dependency(%q<jeweler>, [">= 0"])
48
- s.add_development_dependency(%q<rcov>, [">= 0"])
49
50
  else
50
51
  s.add_dependency(%q<shoulda>, [">= 0"])
51
52
  s.add_dependency(%q<bundler>, [">= 0"])
52
53
  s.add_dependency(%q<jeweler>, [">= 0"])
53
- s.add_dependency(%q<rcov>, [">= 0"])
54
54
  end
55
55
  else
56
56
  s.add_dependency(%q<shoulda>, [">= 0"])
57
57
  s.add_dependency(%q<bundler>, [">= 0"])
58
58
  s.add_dependency(%q<jeweler>, [">= 0"])
59
- s.add_dependency(%q<rcov>, [">= 0"])
60
59
  end
61
60
  end
62
61
 
metadata CHANGED
@@ -1,101 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-merger
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.1
4
+ version: 0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul Schreiber
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-25 00:00:00.000000000 Z
11
+ date: 2014-08-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: shoulda
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ! '>='
19
- - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
22
- none: false
23
15
  requirement: !ruby/object:Gem::Requirement
24
16
  requirements:
25
- - - ! '>='
17
+ - - ">="
26
18
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
30
- prerelease: false
19
+ version: '0'
31
20
  type: :development
32
- - !ruby/object:Gem::Dependency
33
- name: bundler
21
+ prerelease: false
34
22
  version_requirements: !ruby/object:Gem::Requirement
35
23
  requirements:
36
- - - ! '>='
24
+ - - ">="
37
25
  - !ruby/object:Gem::Version
38
- version: !binary |-
39
- MA==
40
- none: false
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
41
29
  requirement: !ruby/object:Gem::Requirement
42
30
  requirements:
43
- - - ! '>='
31
+ - - ">="
44
32
  - !ruby/object:Gem::Version
45
- version: !binary |-
46
- MA==
47
- none: false
48
- prerelease: false
33
+ version: '0'
49
34
  type: :development
50
- - !ruby/object:Gem::Dependency
51
- name: jeweler
35
+ prerelease: false
52
36
  version_requirements: !ruby/object:Gem::Requirement
53
37
  requirements:
54
- - - ! '>='
38
+ - - ">="
55
39
  - !ruby/object:Gem::Version
56
- version: !binary |-
57
- MA==
58
- none: false
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
59
43
  requirement: !ruby/object:Gem::Requirement
60
44
  requirements:
61
- - - ! '>='
45
+ - - ">="
62
46
  - !ruby/object:Gem::Version
63
- version: !binary |-
64
- MA==
65
- none: false
66
- prerelease: false
47
+ version: '0'
67
48
  type: :development
68
- - !ruby/object:Gem::Dependency
69
- name: rcov
49
+ prerelease: false
70
50
  version_requirements: !ruby/object:Gem::Requirement
71
51
  requirements:
72
- - - ! '>='
52
+ - - ">="
73
53
  - !ruby/object:Gem::Version
74
- version: !binary |-
75
- MA==
76
- none: false
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ! '>='
80
- - !ruby/object:Gem::Version
81
- version: !binary |-
82
- MA==
83
- none: false
84
- prerelease: false
85
- type: :development
54
+ version: '0'
86
55
  description: Merge multiple PDFs in to one using iText's PdfCopyFile.
87
56
  email: paulschreiber@gmail.com
88
57
  executables: []
89
58
  extensions: []
90
59
  extra_rdoc_files:
91
60
  - LICENSE.txt
92
- - README.txt
61
+ - README.md
93
62
  files:
63
+ - Carrierwave.md
94
64
  - Gemfile
95
65
  - Gemfile.lock
96
66
  - History.txt
97
67
  - LICENSE.txt
98
- - README.txt
68
+ - README.md
99
69
  - Rakefile
100
70
  - VERSION
101
71
  - ext/iText-4.2.0.jar
@@ -108,31 +78,25 @@ files:
108
78
  homepage: http://github.com/paulschreiber/pdf-merger
109
79
  licenses:
110
80
  - MIT
111
- post_install_message:
81
+ metadata: {}
82
+ post_install_message:
112
83
  rdoc_options: []
113
84
  require_paths:
114
85
  - lib
115
86
  required_ruby_version: !ruby/object:Gem::Requirement
116
87
  requirements:
117
- - - ! '>='
88
+ - - ">="
118
89
  - !ruby/object:Gem::Version
119
- segments:
120
- - 0
121
- hash: 2
122
- version: !binary |-
123
- MA==
124
- none: false
90
+ version: '0'
125
91
  required_rubygems_version: !ruby/object:Gem::Requirement
126
92
  requirements:
127
- - - ! '>='
93
+ - - ">="
128
94
  - !ruby/object:Gem::Version
129
- version: !binary |-
130
- MA==
131
- none: false
95
+ version: '0'
132
96
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 1.8.24
135
- signing_key:
136
- specification_version: 3
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.0
99
+ signing_key:
100
+ specification_version: 4
137
101
  summary: Merge PDFs.
138
102
  test_files: []
data/README.txt DELETED
@@ -1,27 +0,0 @@
1
- = pdf/merger - PDF Merging
2
- http://github.com/paulschreiber/pdf-merger/
3
- by Paul Schreiber
4
-
5
- Merge PDFs using iText.
6
-
7
- == Example
8
-
9
- require "pdf/merger"
10
- failure_list = []
11
- pdf = PDF::Merger.new
12
- pdf.add_file "foo.pdf"
13
- pdf.add_file "bar.pdf"
14
- pdf.add_javascript "this.print(true);"
15
- pdf.save_as "combined.pdf", failure_list
16
-
17
- == Encoding
18
-
19
- On some systems, such as Linux, you need to manually set the encoding. If you don't do that, merging on filenames with special characters will fail with a java.io.IOEXception (not found as file or resource).
20
-
21
- I added this line to my environments/production.rb to fix the problem:
22
- ENV["LC_ALL"] = "en_US.utf8"
23
-
24
- == License
25
-
26
- Copyright 2010-12 Paul Schreiber. Released under the MIT License.
27
- See LICENSE.txt for further details.