pdfunite 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +4 -2
- data/README.md +2 -1
- data/lib/pdfunite.rb +22 -12
- data/lib/pdfunite/version.rb +1 -1
- metadata +3 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5cd07900239253b89f736e0bc2afaa4dfddf82b295c40727cc6db334af7b7422
|
4
|
+
data.tar.gz: 4a11eb86bdf95d083a835a42639bb840a7fe372e3e9377dde1e0fb6e37f440c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42098f2bd77ce44e2ad7cc9a1446e9d31e2f506beaa0b0604613d9eb3cde43912118b79890ea431b901c3d63e95b4e1a14f5478115ec2c9059d7eb69c0f7f8e7
|
7
|
+
data.tar.gz: 72ef4ee8e99caad4de5ef4fb4c62ba406c04565c4241d2067006bf935cf9589146d587405b80a25d91dfdd1dbfa799281805041b6c9dc7eb68a0e943bdd909a4
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/pdfunite.svg)](http://badge.fury.io/rb/pdfunite) [![Build Status](https://travis-ci.org/mtgrosser/pdfunite.svg)](https://travis-ci.org/mtgrosser/pdfunite)
|
1
2
|
# Pdfunite
|
2
3
|
|
3
4
|
Merge PDF files with Ruby.
|
@@ -30,7 +31,7 @@ gem 'pdfunite'
|
|
30
31
|
```ruby
|
31
32
|
# Join existing PDF files
|
32
33
|
pdf_data = Pdfunite.join('file1.pdf', 'file2.pdf', 'file3.pdf')
|
33
|
-
File.open('joined.pdf', 'wb') { f << pdf_data }
|
34
|
+
File.open('joined.pdf', 'wb') { |f| f << pdf_data }
|
34
35
|
|
35
36
|
# Join PDF binary data provided by a collection of objects
|
36
37
|
pdf_data = Pdfunite.join(objects) { |obj| obj.to_pdf }
|
data/lib/pdfunite.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'pdfunite/version'
|
2
2
|
require 'tmpdir'
|
3
3
|
require 'pathname'
|
4
|
-
require '
|
4
|
+
require 'open3'
|
5
|
+
require 'shellwords'
|
5
6
|
require 'logger'
|
6
7
|
|
7
8
|
module Pdfunite
|
@@ -42,8 +43,7 @@ module Pdfunite
|
|
42
43
|
output = nil
|
43
44
|
Dir.mktmpdir do |dir|
|
44
45
|
tmpdir = Pathname.new(dir).realpath
|
45
|
-
files = args.flatten(1).
|
46
|
-
idx = hsh.size
|
46
|
+
files = args.flatten(1).collect.with_index do |arg, idx|
|
47
47
|
realpath = if block_given?
|
48
48
|
data = yield(arg)
|
49
49
|
file = tmpdir.join("#{idx}.pdf")
|
@@ -52,19 +52,29 @@ module Pdfunite
|
|
52
52
|
else
|
53
53
|
Pathname.new(arg).realpath
|
54
54
|
end
|
55
|
-
|
55
|
+
realpath.to_s
|
56
56
|
end
|
57
|
-
cmdline = Cocaine::CommandLine.new(binary, "#{files.keys.map(&:inspect).join(' ')} :outfile", logger: Pdfunite.logger || Logger.new(STDOUT))
|
58
57
|
outfile = tmpdir.join('output.pdf')
|
59
|
-
|
60
|
-
|
61
|
-
rescue Cocaine::CommandNotFoundError
|
62
|
-
raise BinaryNotFound, "The pdfunite executable could not be found at #{binary.inspect}. Check the pdfunite README for more info."
|
63
|
-
end
|
64
|
-
output = outfile.binread
|
58
|
+
cmdline = [binary.to_s, *files, outfile.to_s]
|
59
|
+
output = outfile.binread if run_command(cmdline.shelljoin)
|
65
60
|
end
|
66
61
|
output
|
67
62
|
end
|
68
|
-
end
|
69
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
|
70
80
|
end
|
data/lib/pdfunite/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfunite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
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
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
112
|
- !ruby/object:Gem::Version
|
127
113
|
version: '0'
|
128
114
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.2.2
|
115
|
+
rubygems_version: 3.0.3
|
131
116
|
signing_key:
|
132
117
|
specification_version: 4
|
133
118
|
summary: Merge PDF files with Ruby - no Java required
|