pdfunite 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +16 -0
- data/LICENSE +22 -0
- data/README.md +3 -8
- data/lib/pdfunite/version.rb +1 -1
- data/lib/pdfunite.rb +44 -11
- metadata +8 -93
- data/Gemfile +0 -3
- data/Rakefile +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 881640b13ebaaf28fb9832ec38da781d2cfbb7dd43e204d86ff661b4179f2c4e
|
4
|
+
data.tar.gz: 8a6cb2057f577fdf560e0728874e025760e366b9292777ed39ce4e26406cd51c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0c5c177b799a095f3d5066af73c456c25b3237ae59037f547630aa166d7f63f151919a34ddfbeed62a98288b1413c2312b1d75b31f5b3688a28b4f58042fa1
|
7
|
+
data.tar.gz: 8a0c76dc2d6773fdbdcfe52bbfb37d0e96e634191a2ad85468027751671f1fe82290f248ae8441822462d89f4614a760e50e63b0371bd02d3c53ba5a505d8b95
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## 0.6.0 - Nov 19, 2021
|
2
|
+
|
3
|
+
- Cleanup dependencies
|
4
|
+
- Test for Ruby 2.6, 2.7 and 3.0
|
5
|
+
|
6
|
+
## 0.5.0 - Jul 4, 2019
|
7
|
+
|
8
|
+
- Drop cocaine dependency
|
9
|
+
|
10
|
+
## 0.3.0 - Dec 6, 2014
|
11
|
+
|
12
|
+
- Do not read existing files, use paths instead
|
13
|
+
|
14
|
+
## 0.2.0 - Nov 27, 2014
|
15
|
+
|
16
|
+
- added Pdfunite.binary configuration option
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Matthias Grosser
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/pdfunite.svg)](http://badge.fury.io/rb/pdfunite)
|
2
|
+
[![build](https://github.com/mtgrosser/pdfunite/actions/workflows/build.yml/badge.svg)](https://github.com/mtgrosser/pdfunite/actions/workflows/build.yml)
|
1
3
|
# Pdfunite
|
2
4
|
|
3
5
|
Merge PDF files with Ruby.
|
@@ -30,15 +32,8 @@ gem 'pdfunite'
|
|
30
32
|
```ruby
|
31
33
|
# Join existing PDF files
|
32
34
|
pdf_data = Pdfunite.join('file1.pdf', 'file2.pdf', 'file3.pdf')
|
35
|
+
File.open('joined.pdf', 'wb') { |f| f << pdf_data }
|
33
36
|
|
34
37
|
# Join PDF binary data provided by a collection of objects
|
35
38
|
pdf_data = Pdfunite.join(objects) { |obj| obj.to_pdf }
|
36
39
|
```
|
37
|
-
|
38
|
-
## Contributing
|
39
|
-
|
40
|
-
1. Fork it ( https://github.com/[my-github-username]/pdfunite/fork )
|
41
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
-
5. Create a new Pull Request
|
data/lib/pdfunite/version.rb
CHANGED
data/lib/pdfunite.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'pdfunite/version'
|
2
|
+
require 'tmpdir'
|
2
3
|
require 'pathname'
|
3
|
-
require '
|
4
|
+
require 'open3'
|
5
|
+
require 'shellwords'
|
4
6
|
require 'logger'
|
5
7
|
|
6
8
|
module Pdfunite
|
7
9
|
|
10
|
+
class BinaryNotFound < StandardError; end
|
11
|
+
|
8
12
|
class << self
|
9
13
|
|
10
14
|
@@logger = nil
|
@@ -18,6 +22,17 @@ module Pdfunite
|
|
18
22
|
@@logger
|
19
23
|
end
|
20
24
|
|
25
|
+
@@binary = 'pdfunite'
|
26
|
+
|
27
|
+
# You can set a custom pdfunite binary here
|
28
|
+
def binary=(binary)
|
29
|
+
@@binary = binary
|
30
|
+
end
|
31
|
+
|
32
|
+
def binary
|
33
|
+
@@binary
|
34
|
+
end
|
35
|
+
|
21
36
|
#
|
22
37
|
# Join PDF files or PDF data
|
23
38
|
#
|
@@ -28,20 +43,38 @@ module Pdfunite
|
|
28
43
|
output = nil
|
29
44
|
Dir.mktmpdir do |dir|
|
30
45
|
tmpdir = Pathname.new(dir).realpath
|
31
|
-
files = args.flatten(1).
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
files = args.flatten(1).collect.with_index do |arg, idx|
|
47
|
+
realpath = if block_given?
|
48
|
+
data = yield(arg)
|
49
|
+
file = tmpdir.join("#{idx}.pdf")
|
50
|
+
file.open('wb') { |f| f << data }
|
51
|
+
file.realpath
|
52
|
+
else
|
53
|
+
Pathname.new(arg).realpath
|
54
|
+
end
|
55
|
+
realpath.to_s
|
37
56
|
end
|
38
|
-
cmdline = Cocaine::CommandLine.new('pdfunite', "#{files.keys.map(&:inspect).join(' ')} :outfile", logger: Pdfunite.logger || Logger.new(STDOUT))
|
39
57
|
outfile = tmpdir.join('output.pdf')
|
40
|
-
cmdline.
|
41
|
-
output = outfile.binread
|
58
|
+
cmdline = [binary.to_s, *files, outfile.to_s]
|
59
|
+
output = outfile.binread if run_command(cmdline.shelljoin)
|
42
60
|
end
|
43
61
|
output
|
44
62
|
end
|
45
|
-
end
|
46
63
|
|
64
|
+
private
|
65
|
+
|
66
|
+
def run_command(cmdline)
|
67
|
+
logger = Pdfunite.logger || Logger.new(STDOUT)
|
68
|
+
stdout, stderr, status = Open3.capture3(cmdline)
|
69
|
+
logger.info "Pdfunite: #{cmdline}"
|
70
|
+
raise unless status.success?
|
71
|
+
true
|
72
|
+
rescue Errno::ENOENT
|
73
|
+
raise BinaryNotFound, "The pdfunite executable could not be found at #{binary.inspect}. Check the pdfunite README for more info."
|
74
|
+
rescue => e
|
75
|
+
logger.error "Pdfunite error: #{e}\ncommand: #{cmdline}\nerror: #{stderr}"
|
76
|
+
false
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
47
80
|
end
|
metadata
CHANGED
@@ -1,109 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfunite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: cocaine
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.5'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.5'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.7'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.7'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: simplecov
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: byebug
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: minitest
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '5.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '5.0'
|
97
|
-
description: Ruby wrapper for the pdfunite command line tool. No Java required
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby wrapper for the pdfunite command line tool
|
98
14
|
email:
|
99
15
|
- mtgrosser@gmx.net
|
100
16
|
executables: []
|
101
17
|
extensions: []
|
102
18
|
extra_rdoc_files: []
|
103
19
|
files:
|
104
|
-
-
|
20
|
+
- CHANGELOG.md
|
21
|
+
- LICENSE
|
105
22
|
- README.md
|
106
|
-
- Rakefile
|
107
23
|
- lib/pdfunite.rb
|
108
24
|
- lib/pdfunite/version.rb
|
109
25
|
homepage: https://github.com/mtgrosser/pdfunite
|
@@ -125,9 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
41
|
- !ruby/object:Gem::Version
|
126
42
|
version: '0'
|
127
43
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.2.2
|
44
|
+
rubygems_version: 3.1.4
|
130
45
|
signing_key:
|
131
46
|
specification_version: 4
|
132
|
-
summary: Merge PDF files with Ruby
|
47
|
+
summary: Merge PDF files with Ruby - no Java required
|
133
48
|
test_files: []
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rdoc/task'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Run all tests'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.test_files = FileList['test/unit/*_test.rb']
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Generate documentation'
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = 'Pdfunite'
|
19
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README.md')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|