pdf-merger 0.1.1
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.
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/History.txt +7 -0
- data/LICENSE.txt +20 -0
- data/README.txt +25 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/ext/iText-4.2.0.jar +0 -0
- data/lib/pdf/merger.rb +40 -0
- data/lib/pdf/merger/jruby.rb +29 -0
- data/lib/pdf/merger/rjb.rb +38 -0
- data/pdf-merger.gemspec +63 -0
- data/spec/pdf_merger_spec.rb +20 -0
- data/spec/test_template.pdf +0 -0
- metadata +127 -0
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.9.2)
|
10
|
+
rcov (0.9.10)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.6.4)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2011 Paul Schreiber
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,25 @@
|
|
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
|
+
pdf = PDF::Merger.new
|
11
|
+
pdf.add_file "foo.pdf"
|
12
|
+
pdf.add_file "bar.pdf"
|
13
|
+
pdf.save_as "combined.pdf"
|
14
|
+
|
15
|
+
== Encoding
|
16
|
+
|
17
|
+
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).
|
18
|
+
|
19
|
+
I added this line to my environments/production.rb to fix the problem:
|
20
|
+
ENV["LC_ALL"] = "en_US.utf8"
|
21
|
+
|
22
|
+
== License
|
23
|
+
|
24
|
+
Copyright (c) 2011 Paul Schreiber. Released under the MIT License.
|
25
|
+
See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "pdf-merger"
|
18
|
+
gem.homepage = "http://github.com/paulschreiber/pdf-merger"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Merge PDFs.}
|
21
|
+
gem.description = %Q{Merge multiple PDFs in to one using iText's PdfCopyFile.}
|
22
|
+
gem.email = "paulschreiber@gmail.com"
|
23
|
+
gem.authors = ["Paul Schreiber"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
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
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "pdf-merger #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/ext/iText-4.2.0.jar
ADDED
Binary file
|
data/lib/pdf/merger.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# = pdf/merger.rb -- PDF merging
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010 Paul Schreiber
|
4
|
+
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'tmpdir'
|
8
|
+
|
9
|
+
include FileUtils
|
10
|
+
|
11
|
+
module PDF
|
12
|
+
class Merger
|
13
|
+
VERSION = "0.1.1"
|
14
|
+
|
15
|
+
if RUBY_PLATFORM =~ /java/ # ifdef to check if your using JRuby
|
16
|
+
require 'pdf/merger/jruby'
|
17
|
+
else
|
18
|
+
require 'pdf/merger/rjb'
|
19
|
+
end
|
20
|
+
# PDF::Merger provides an interface into iText allowing for the
|
21
|
+
# merging of PDFs.
|
22
|
+
#
|
23
|
+
# == Example
|
24
|
+
#
|
25
|
+
# pdf = PDF::Merger.new
|
26
|
+
# pdf.add_file "foo.pdf"
|
27
|
+
# pdf.add_file "bar.pdf"
|
28
|
+
# pdf.save_as "combined.pdf"
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@files_to_merge = []
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_file(file_path)
|
35
|
+
@files_to_merge << file_path
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# = pdf/merger/rjb.rb -- PDF template stamping.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010 Paul Schreiber
|
4
|
+
|
5
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'ext'))
|
6
|
+
require 'java'
|
7
|
+
require 'iText-4.2.0.jar'
|
8
|
+
|
9
|
+
include_class 'java.io.FileOutputStream'
|
10
|
+
include_class 'com.lowagie.text.pdf.PdfReader'
|
11
|
+
include_class 'com.lowagie.text.pdf.PdfCopyFields'
|
12
|
+
|
13
|
+
module PDF
|
14
|
+
class Merger
|
15
|
+
|
16
|
+
# Saves the PDF into a file defined by path given.
|
17
|
+
def save_as(output_file_path)
|
18
|
+
filestream = FileOutputStream.new(output_file_path)
|
19
|
+
copy = PdfCopyFields.new(filestream)
|
20
|
+
|
21
|
+
@files_to_merge.each do |f|
|
22
|
+
copy.addDocument(PdfReader.new(f))
|
23
|
+
end
|
24
|
+
|
25
|
+
copy.close()
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# = pdf/merger/rjb.rb -- PDF template stamping.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010 Paul Schreiber
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rjb'
|
7
|
+
|
8
|
+
Rjb::load(File.join(File.dirname(__FILE__), '..', '..', '..', 'ext', 'iText-4.2.0.jar'), ['-Djava.awt.headless=true'])
|
9
|
+
|
10
|
+
module PDF
|
11
|
+
# PDF::Merger::RJB
|
12
|
+
#
|
13
|
+
# RJB needs the LD_LIBRARY_PATH and JAVA_HOME environment set for it
|
14
|
+
# to work correctly. For example on my system:
|
15
|
+
#
|
16
|
+
# export LD_LIBRARY_PATH=/usr/java/jdk1.6.0/jre/lib/i386/:/usr/java/jdk1.6.0/jre/lib/i386/client/:./
|
17
|
+
# export JAVA_HOME=/usr/java/jdk1.6.0/
|
18
|
+
#
|
19
|
+
# Check the RJB documentation if you are having issues with this.
|
20
|
+
class Merger
|
21
|
+
# Saves the PDF into a file defined by path given.
|
22
|
+
def save_as(output_file_path)
|
23
|
+
@pdfreader = Rjb::import('com.lowagie.text.pdf.PdfReader')
|
24
|
+
@pdfcopyfields = Rjb::import('com.lowagie.text.pdf.PdfCopyFields')
|
25
|
+
@filestream = Rjb::import('java.io.FileOutputStream')
|
26
|
+
|
27
|
+
filestream = @filestream.new(output_file_path)
|
28
|
+
copy = @pdfcopyfields.new(filestream)
|
29
|
+
|
30
|
+
@files_to_merge.each do |f|
|
31
|
+
copy.addDocument(@pdfreader.new(f))
|
32
|
+
end
|
33
|
+
|
34
|
+
copy.close()
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/pdf-merger.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pdf-merger}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Schreiber"]
|
12
|
+
s.date = %q{2011-09-10}
|
13
|
+
s.description = %q{Merge multiple PDFs in to one using iText's PdfCopyFile.}
|
14
|
+
s.email = %q{paulschreiber@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.txt"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"History.txt",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.txt",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"ext/iText-4.2.0.jar",
|
28
|
+
"lib/pdf/merger.rb",
|
29
|
+
"lib/pdf/merger/jruby.rb",
|
30
|
+
"lib/pdf/merger/rjb.rb",
|
31
|
+
"pdf-merger.gemspec",
|
32
|
+
"spec/pdf_merger_spec.rb",
|
33
|
+
"spec/test_template.pdf"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/paulschreiber/pdf-merger}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.6}
|
39
|
+
s.summary = %q{Merge PDFs.}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
49
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
54
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'pdf/merger'
|
3
|
+
|
4
|
+
describe PDF::Merger do
|
5
|
+
before(:each) do
|
6
|
+
@pdf = PDF::Merger.new
|
7
|
+
@pdf.add_file :text_field01, "test_template.pdf"
|
8
|
+
@pdf.add_file :text_field02, "test_template.pdf"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create PDF document" do
|
12
|
+
@pdf.to_s.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should save PDF document" do
|
16
|
+
@pdf.save_as "test_output.pdf"
|
17
|
+
File.exist?("test_output.pdf").should be_true
|
18
|
+
File.delete("test_output.pdf") # Comment this out to view the output
|
19
|
+
end
|
20
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdf-merger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Paul Schreiber
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-09-10 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
type: :development
|
23
|
+
name: shoulda
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
name: bundler
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
version: 1.0.0
|
45
|
+
requirement: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
name: jeweler
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 1
|
56
|
+
- 6
|
57
|
+
- 4
|
58
|
+
version: 1.6.4
|
59
|
+
requirement: *id003
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
prerelease: false
|
62
|
+
type: :development
|
63
|
+
name: rcov
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirement: *id004
|
72
|
+
description: Merge multiple PDFs in to one using iText's PdfCopyFile.
|
73
|
+
email: paulschreiber@gmail.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files:
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.txt
|
81
|
+
files:
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- History.txt
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.txt
|
87
|
+
- Rakefile
|
88
|
+
- VERSION
|
89
|
+
- ext/iText-4.2.0.jar
|
90
|
+
- lib/pdf/merger.rb
|
91
|
+
- lib/pdf/merger/jruby.rb
|
92
|
+
- lib/pdf/merger/rjb.rb
|
93
|
+
- pdf-merger.gemspec
|
94
|
+
- spec/pdf_merger_spec.rb
|
95
|
+
- spec/test_template.pdf
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://github.com/paulschreiber/pdf-merger
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Merge PDFs.
|
126
|
+
test_files: []
|
127
|
+
|