pdfmult 1.2.0 → 1.3.0
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/README.md +4 -0
- data/lib/pdfmult.rb +49 -21
- data/man/pdfmult.1 +8 -4
- data/pdfmult.gemspec +1 -1
- data/pdfmult.h2m +1 -0
- data/test/test_optionparser.rb +17 -1
- metadata +53 -61
data/README.md
CHANGED
data/lib/pdfmult.rb
CHANGED
@@ -27,15 +27,18 @@
|
|
27
27
|
#
|
28
28
|
# -n, --number:: Number of copies to put on one page: 2 (default), 4, 8, 9, 16.
|
29
29
|
#
|
30
|
-
# -f, --force:: Do not prompt before overwriting.
|
30
|
+
# -f, --[no-]force:: Do not prompt before overwriting.
|
31
31
|
#
|
32
32
|
# -l, --latex:: Create a LaTeX file instead of a PDF file (default: infile_NUMBER.tex).
|
33
33
|
#
|
34
34
|
# -o, --output:: Output file (default: infile_NUMBER.pdf).
|
35
|
+
# Use - to output to stdout.
|
35
36
|
#
|
36
37
|
# -p, --pages:: Number of pages to convert.
|
37
38
|
# If given, +pdfmult+ does not try to obtain the page count from the source PDF.
|
38
39
|
#
|
40
|
+
# -s, --[no-]silent:: Do not output progress information.
|
41
|
+
#
|
39
42
|
# -h, --help:: Prints a brief help message and exits.
|
40
43
|
#
|
41
44
|
# -v, --version:: Prints a brief version information and exits.
|
@@ -46,6 +49,7 @@
|
|
46
49
|
# pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
47
50
|
# pdfmult sample.pdf -o outfile.pdf # => outfile.pdf (2 copies)
|
48
51
|
# pdfmult sample.pdf -p 3 # => processes 3 pages
|
52
|
+
# pdfmult sample.pdf -o - | lpr # => sends output via stdout to print command
|
49
53
|
#
|
50
54
|
# == Author
|
51
55
|
#
|
@@ -58,17 +62,18 @@
|
|
58
62
|
require 'optparse'
|
59
63
|
require 'tempfile'
|
60
64
|
require 'fileutils'
|
65
|
+
require 'open3'
|
61
66
|
|
62
|
-
# This module contains the classes for the +pdfmult+ tool
|
67
|
+
# This module contains the classes for the +pdfmult+ tool.
|
63
68
|
module Pdfmult
|
64
69
|
|
65
70
|
PROGNAME = 'pdfmult'
|
66
|
-
VERSION = '1.
|
67
|
-
DATE = '2012-
|
71
|
+
VERSION = '1.3.0'
|
72
|
+
DATE = '2012-09-22'
|
68
73
|
HOMEPAGE = 'https://github.com/stomar/pdfmult/'
|
69
74
|
|
70
75
|
COPYRIGHT = "Copyright (C) 2011-2012 Marcus Stollsteimer.\n" +
|
71
|
-
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
|
76
|
+
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" +
|
72
77
|
"This is free software: you are free to change and redistribute it.\n" +
|
73
78
|
"There is NO WARRANTY, to the extent permitted by law."
|
74
79
|
|
@@ -94,6 +99,7 @@ module Pdfmult
|
|
94
99
|
:latex => false,
|
95
100
|
:number => 2,
|
96
101
|
:outfile => nil,
|
102
|
+
:silent => false,
|
97
103
|
:pages => nil
|
98
104
|
}
|
99
105
|
|
@@ -138,8 +144,8 @@ module Pdfmult
|
|
138
144
|
options[:number] = n
|
139
145
|
end
|
140
146
|
|
141
|
-
opt.on('-f', '--force', 'Do not prompt before overwriting.') do
|
142
|
-
options[:force] =
|
147
|
+
opt.on('-f', '--[no-]force', 'Do not prompt before overwriting.') do |f|
|
148
|
+
options[:force] = f
|
143
149
|
end
|
144
150
|
|
145
151
|
opt.on('-l', '--latex', 'Create a LaTeX file instead of a PDF file (default: file_2.tex).') do
|
@@ -147,7 +153,7 @@ module Pdfmult
|
|
147
153
|
end
|
148
154
|
|
149
155
|
opt.on('-o', '--output FILE', String,
|
150
|
-
'Output file (default: file_2.pdf).') do |f|
|
156
|
+
'Output file (default: file_2.pdf). Use - to output to stdout.') do |f|
|
151
157
|
options[:outfile] = f
|
152
158
|
end
|
153
159
|
|
@@ -158,6 +164,10 @@ module Pdfmult
|
|
158
164
|
options[:pages] = p
|
159
165
|
end
|
160
166
|
|
167
|
+
opt.on('-s', '--[no-]silent', 'Do not output progress information.') do |s|
|
168
|
+
options[:silent] = s
|
169
|
+
end
|
170
|
+
|
161
171
|
opt.separator ''
|
162
172
|
end
|
163
173
|
opt_parser.parse!(argv)
|
@@ -198,7 +208,7 @@ module Pdfmult
|
|
198
208
|
"\\includepdf[pages={PAGES},nup=GEOMETRY]{FILENAME}%\n"
|
199
209
|
|
200
210
|
FOOTER =
|
201
|
-
|
211
|
+
"\\end{document}\n"
|
202
212
|
|
203
213
|
# Initializes a LaTeXDocument instance.
|
204
214
|
#
|
@@ -230,7 +240,10 @@ module Pdfmult
|
|
230
240
|
geometry = '4x4'
|
231
241
|
end
|
232
242
|
|
233
|
-
content_template = CONTENT.gsub(/PAGES
|
243
|
+
content_template = CONTENT.gsub(/PAGES|GEOMETRY|FILENAME/,
|
244
|
+
'PAGES' => page_string,
|
245
|
+
'GEOMETRY' => geometry,
|
246
|
+
'FILENAME' => @infile)
|
234
247
|
|
235
248
|
content = HEADER.gsub(/CLASSOPTIONS/, class_options)
|
236
249
|
@page_count.times do |i|
|
@@ -299,6 +312,8 @@ module Pdfmult
|
|
299
312
|
|
300
313
|
infile = options[:infile]
|
301
314
|
outfile = options[:outfile]
|
315
|
+
use_stdout = (outfile == '-')
|
316
|
+
silent = options[:silent]
|
302
317
|
|
303
318
|
# test for pdflatex installation
|
304
319
|
unless options[:latex]
|
@@ -312,7 +327,7 @@ module Pdfmult
|
|
312
327
|
usage_fail("specified input not of the type `file'") unless File.ftype(infile) == 'file'
|
313
328
|
|
314
329
|
# test for existing output file
|
315
|
-
if
|
330
|
+
if !use_stdout and !options[:force] and File.exist?(outfile)
|
316
331
|
overwrite_ok = ask("File `#{outfile}' already exists. Overwrite?")
|
317
332
|
exit unless overwrite_ok
|
318
333
|
end
|
@@ -326,16 +341,29 @@ module Pdfmult
|
|
326
341
|
document = LaTeXDocument.new(infile, options[:number], pages)
|
327
342
|
|
328
343
|
if options[:latex]
|
329
|
-
|
344
|
+
if use_stdout
|
345
|
+
puts document.to_s
|
346
|
+
else
|
347
|
+
warn "Writing on #{outfile}." unless silent
|
348
|
+
open(outfile, 'w') {|f| f.write(document.to_s) }
|
349
|
+
end
|
330
350
|
else
|
331
351
|
Dir.mktmpdir('pdfmult') do |dir|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
352
|
+
texfile = 'pdfmult.tex'
|
353
|
+
pdffile = 'pdfmult.pdf'
|
354
|
+
open("#{dir}/#{texfile}", 'w') {|f| f.write(document.to_s) }
|
355
|
+
command = "#{PDFLATEX} -output-directory #{dir} #{texfile}"
|
356
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
357
|
+
stdout.each_line {|line| warn line.chomp } unless silent # redirect progress messages to stderr
|
358
|
+
stderr.read # make sure all streams are read (and command has finished)
|
359
|
+
end
|
360
|
+
if use_stdout
|
361
|
+
File.open("#{dir}/#{pdffile}") do |f|
|
362
|
+
f.each_line {|line| puts line }
|
363
|
+
end
|
364
|
+
else
|
365
|
+
warn "Writing on #{outfile}." unless silent
|
366
|
+
FileUtils::mv("#{dir}/#{pdffile}", outfile)
|
339
367
|
end
|
340
368
|
end
|
341
369
|
end
|
@@ -348,11 +376,11 @@ module Pdfmult
|
|
348
376
|
# Returns +true+ if the answer is yes.
|
349
377
|
def self.ask(question) # :nodoc:
|
350
378
|
while true
|
351
|
-
print "#{question} [y/n] "
|
379
|
+
$stderr.print "#{question} [y/n] "
|
352
380
|
reply = $stdin.gets.chomp.downcase # $stdin: avoids gets / ARGV problem
|
353
381
|
return true if reply == 'y'
|
354
382
|
return false if reply == 'n'
|
355
|
-
|
383
|
+
warn "Please answer `y' or `n'."
|
356
384
|
end
|
357
385
|
end
|
358
386
|
|
data/man/pdfmult.1
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.40.4.
|
2
|
-
.TH PDFMULT "1" "
|
2
|
+
.TH PDFMULT "1" "September 2012" "pdfmult 1.3.0" "User Commands"
|
3
3
|
.SH NAME
|
4
4
|
pdfmult \- puts multiple copies of a PDF page on one page
|
5
5
|
.SH SYNOPSIS
|
@@ -25,19 +25,22 @@ and a LaTeX file is created instead of a PDF.
|
|
25
25
|
\fB\-n\fR, \fB\-\-number\fR NUMBER
|
26
26
|
Number of copies to put on one page: 2 (default), 4, 8, 9, 16.
|
27
27
|
.TP
|
28
|
-
\fB\-f\fR, \fB\-\-force\fR
|
28
|
+
\fB\-f\fR, \fB\-\-[no\-]force\fR
|
29
29
|
Do not prompt before overwriting.
|
30
30
|
.TP
|
31
31
|
\fB\-l\fR, \fB\-\-latex\fR
|
32
32
|
Create a LaTeX file instead of a PDF file (default: file_2.tex).
|
33
33
|
.TP
|
34
34
|
\fB\-o\fR, \fB\-\-output\fR FILE
|
35
|
-
Output file (default: file_2.pdf).
|
35
|
+
Output file (default: file_2.pdf). Use \- to output to stdout.
|
36
36
|
.TP
|
37
37
|
\fB\-p\fR, \fB\-\-pages\fR NUMBER
|
38
38
|
Number of pages to convert.
|
39
39
|
If given, pdfmult does not try to obtain the page count from the source PDF.
|
40
40
|
.TP
|
41
|
+
\fB\-s\fR, \fB\-\-[no\-]silent\fR
|
42
|
+
Do not output progress information.
|
43
|
+
.TP
|
41
44
|
\fB\-h\fR, \fB\-\-help\fR
|
42
45
|
Prints a brief help message and exits.
|
43
46
|
.TP
|
@@ -48,12 +51,13 @@ Prints a brief version information and exits.
|
|
48
51
|
pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
49
52
|
pdfmult sample.pdf -o outfile.pdf # => outfile.pdf (2 copies)
|
50
53
|
pdfmult sample.pdf -p 3 # => processes 3 pages
|
54
|
+
pdfmult sample.pdf -o - | lpr # => sends output via stdout to print command
|
51
55
|
.SH "REPORTING BUGS"
|
52
56
|
Report bugs on the pdfmult home page: <https://github.com/stomar/pdfmult/>
|
53
57
|
.SH COPYRIGHT
|
54
58
|
Copyright \(co 2011\-2012 Marcus Stollsteimer.
|
55
59
|
.br
|
56
|
-
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
|
60
|
+
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
57
61
|
.br
|
58
62
|
This is free software: you are free to change and redistribute it.
|
59
63
|
.br
|
data/pdfmult.gemspec
CHANGED
data/pdfmult.h2m
CHANGED
@@ -6,3 +6,4 @@ pdfmult \- puts multiple copies of a PDF page on one page
|
|
6
6
|
pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
7
7
|
pdfmult sample.pdf -o outfile.pdf # => outfile.pdf (2 copies)
|
8
8
|
pdfmult sample.pdf -p 3 # => processes 3 pages
|
9
|
+
pdfmult sample.pdf -o - | lpr # => sends output via stdout to print command
|
data/test/test_optionparser.rb
CHANGED
@@ -18,7 +18,8 @@ describe Pdfmult::Optionparser do
|
|
18
18
|
:latex => false,
|
19
19
|
:number => 2,
|
20
20
|
:outfile => 'sample_2.pdf',
|
21
|
-
:pages => nil
|
21
|
+
:pages => nil,
|
22
|
+
:silent => false
|
22
23
|
}
|
23
24
|
options.must_equal expected
|
24
25
|
end
|
@@ -48,6 +49,11 @@ describe Pdfmult::Optionparser do
|
|
48
49
|
options[:force].must_equal true
|
49
50
|
end
|
50
51
|
|
52
|
+
it 'should recognize the --no-force option' do
|
53
|
+
options = Pdfmult::Optionparser.parse!(['sample.pdf', '--no-force'])
|
54
|
+
options[:force].must_equal false
|
55
|
+
end
|
56
|
+
|
51
57
|
it 'should recognize the -l option and set the corresponding output filename' do
|
52
58
|
options = Pdfmult::Optionparser.parse!(['sample.pdf', '-l'])
|
53
59
|
options[:outfile].must_equal 'sample_2.tex'
|
@@ -60,6 +66,16 @@ describe Pdfmult::Optionparser do
|
|
60
66
|
lambda { Pdfmult::Optionparser.parse!(['sample.pdf', '-p', '-1']) }.must_raise OptionParser::InvalidArgument
|
61
67
|
end
|
62
68
|
|
69
|
+
it 'should recognize the -s option' do
|
70
|
+
options = Pdfmult::Optionparser.parse!(['sample.pdf', '-s'])
|
71
|
+
options[:silent].must_equal true
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should recognize the --no-silent option' do
|
75
|
+
options = Pdfmult::Optionparser.parse!(['sample.pdf', '--no-silent'])
|
76
|
+
options[:silent].must_equal false
|
77
|
+
end
|
78
|
+
|
63
79
|
it 'should not accept wrong number of arguments' do
|
64
80
|
lambda { Pdfmult::Optionparser.parse!(['sample.pdf', 'sample2.pdf']) }.must_raise ArgumentError
|
65
81
|
lambda { Pdfmult::Optionparser.parse!(['']) }.must_raise ArgumentError
|
metadata
CHANGED
@@ -1,59 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfmult
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 1.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Marcus Stollsteimer
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rake
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: minitest
|
36
23
|
prerelease: false
|
37
|
-
|
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: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
38
33
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :development
|
47
|
-
|
48
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: pdfmult is a command line tool that rearranges multiple copies of a PDF
|
47
|
+
page (shrunken) on one page. It is a wrapper for pdflatex with the pdfpages package.
|
49
48
|
email: sto.mar@web.de
|
50
|
-
executables:
|
49
|
+
executables:
|
51
50
|
- pdfmult
|
52
51
|
extensions: []
|
53
|
-
|
54
52
|
extra_rdoc_files: []
|
55
|
-
|
56
|
-
files:
|
53
|
+
files:
|
57
54
|
- README.md
|
58
55
|
- Rakefile
|
59
56
|
- pdfmult.gemspec
|
@@ -71,39 +68,34 @@ files:
|
|
71
68
|
- test/test_optionparser.rb
|
72
69
|
- test/sample.pdf
|
73
70
|
homepage: https://github.com/stomar/pdfmult/
|
74
|
-
licenses:
|
71
|
+
licenses:
|
75
72
|
- GPL-3
|
76
73
|
post_install_message:
|
77
|
-
rdoc_options:
|
74
|
+
rdoc_options:
|
78
75
|
- --charset=UTF-8
|
79
|
-
require_paths:
|
76
|
+
require_paths:
|
80
77
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
79
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
- 0
|
89
|
-
version: "0"
|
90
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
85
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
|
97
|
-
- 0
|
98
|
-
version: "0"
|
99
|
-
requirements:
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements:
|
100
91
|
- pdflatex and the pdfpages package
|
101
92
|
rubyforge_project: pdfmult
|
102
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.24
|
103
94
|
signing_key:
|
104
95
|
specification_version: 3
|
105
96
|
summary: pdfmult - puts multiple copies of a PDF page on one page
|
106
|
-
test_files:
|
97
|
+
test_files:
|
107
98
|
- test/test_pdfinfo.rb
|
108
99
|
- test/test_latex_document.rb
|
109
100
|
- test/test_optionparser.rb
|
101
|
+
has_rdoc:
|