pdfmult 1.3.0 → 1.3.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/README.md +1 -1
- data/Rakefile +10 -2
- data/bin/pdfmult +1 -1
- data/lib/pdfmult.rb +111 -134
- data/man/pdfmult.1 +7 -4
- data/pdfmult.gemspec +2 -1
- data/pdfmult.h2m +4 -3
- data/test/test_latex_document.rb +27 -6
- data/test/test_layout.rb +57 -0
- data/test/test_optionparser.rb +1 -2
- data/test/test_pdfinfo.rb +1 -2
- metadata +62 -52
data/README.md
CHANGED
@@ -68,7 +68,7 @@ As of now, `pdfmult` has only been tested on a Linux system.
|
|
68
68
|
Documentation
|
69
69
|
-------------
|
70
70
|
|
71
|
-
`pdfmult --help`
|
71
|
+
Use `pdfmult --help` to display a brief help message.
|
72
72
|
|
73
73
|
If you installed `pdfmult` using `rake install` you can read
|
74
74
|
its man page with `man pdfmult`.
|
data/Rakefile
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# rakefile for the pdfmult script.
|
2
2
|
#
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2011-2013 Marcus Stollsteimer
|
4
4
|
|
5
5
|
require 'rake/testtask'
|
6
6
|
|
7
|
+
require './lib/pdfmult'
|
8
|
+
|
9
|
+
PROGNAME = Pdfmult::PROGNAME
|
10
|
+
HOMEPAGE = Pdfmult::HOMEPAGE
|
11
|
+
TAGLINE = Pdfmult::TAGLINE
|
12
|
+
|
7
13
|
BINDIR = '/usr/local/bin'
|
8
14
|
MANDIR = '/usr/local/man/man1'
|
9
15
|
|
@@ -52,9 +58,11 @@ desc 'Create man page'
|
|
52
58
|
task :man => [MANPAGE]
|
53
59
|
|
54
60
|
file MANPAGE => [BINARY, H2MFILE] do
|
55
|
-
sh "#{HELP2MAN} --no-info --include=#{H2MFILE} -o #{MANPAGE} ./#{BINARY}"
|
61
|
+
sh "#{HELP2MAN} --no-info --name='#{TAGLINE}' --include=#{H2MFILE} -o #{MANPAGE} ./#{BINARY}"
|
56
62
|
sh "#{SED} -i '/\.PP/{N;s/\.PP\\nOptions/.SH OPTIONS/}' #{MANPAGE}"
|
57
63
|
sh "#{SED} -i 's/^License GPL/.br\\nLicense GPL/;s/There is NO WARRANTY/.br\\nThere is NO WARRANTY/' #{MANPAGE}"
|
64
|
+
sh "#{SED} -i 's!%HOMEPAGE%!#{HOMEPAGE}!g' #{MANPAGE}"
|
65
|
+
sh "#{SED} -i 's!%PROGNAME%!#{PROGNAME}!g' #{MANPAGE}"
|
58
66
|
end
|
59
67
|
|
60
68
|
|
data/bin/pdfmult
CHANGED
data/lib/pdfmult.rb
CHANGED
@@ -1,78 +1,40 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# == Name
|
3
3
|
#
|
4
4
|
# pdfmult - put multiple copies of a PDF page on one page
|
5
5
|
#
|
6
|
-
# == Synopsis
|
7
|
-
#
|
8
|
-
# pdfmult [options] file
|
9
|
-
#
|
10
6
|
# == Description
|
11
7
|
#
|
12
8
|
# +pdfmult+ rearranges multiple copies of a PDF page (shrunken) on one page.
|
13
9
|
#
|
14
|
-
#
|
15
|
-
# the input file is also assumed to be in A4 format.
|
16
|
-
# The input PDF file may consist of several pages.
|
17
|
-
# If +pdfmult+ succeeds in obtaining the page count it will rearrange all pages,
|
18
|
-
# if not, only the first page is processed
|
19
|
-
# (unless the page count was specified via command line option).
|
20
|
-
#
|
21
|
-
# +pdfmult+ uses +pdflatex+ with the +pdfpages+ package,
|
22
|
-
# so both have to be installed on the system.
|
23
|
-
# If the --latex option is used, though, +pdflatex+ is not run
|
24
|
-
# and a LaTeX file is created instead of a PDF.
|
25
|
-
#
|
26
|
-
# == Options
|
27
|
-
#
|
28
|
-
# -n, --number:: Number of copies to put on one page: 2 (default), 4, 8, 9, 16.
|
29
|
-
#
|
30
|
-
# -f, --[no-]force:: Do not prompt before overwriting.
|
31
|
-
#
|
32
|
-
# -l, --latex:: Create a LaTeX file instead of a PDF file (default: infile_NUMBER.tex).
|
33
|
-
#
|
34
|
-
# -o, --output:: Output file (default: infile_NUMBER.pdf).
|
35
|
-
# Use - to output to stdout.
|
36
|
-
#
|
37
|
-
# -p, --pages:: Number of pages to convert.
|
38
|
-
# If given, +pdfmult+ does not try to obtain the page count from the source PDF.
|
39
|
-
#
|
40
|
-
# -s, --[no-]silent:: Do not output progress information.
|
41
|
-
#
|
42
|
-
# -h, --help:: Prints a brief help message and exits.
|
10
|
+
# == See also
|
43
11
|
#
|
44
|
-
#
|
12
|
+
# Use <tt>pdfmult --help</tt> to display a brief help message.
|
45
13
|
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# pdfmult sample.pdf # => sample_2.pdf (2 copies)
|
49
|
-
# pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
50
|
-
# pdfmult sample.pdf -o outfile.pdf # => outfile.pdf (2 copies)
|
51
|
-
# pdfmult sample.pdf -p 3 # => processes 3 pages
|
52
|
-
# pdfmult sample.pdf -o - | lpr # => sends output via stdout to print command
|
14
|
+
# The full documentation for +pdfmult+ is available on the
|
15
|
+
# project home page.
|
53
16
|
#
|
54
17
|
# == Author
|
55
18
|
#
|
56
|
-
# Copyright (C) 2011-
|
19
|
+
# Copyright (C) 2011-2013 Marcus Stollsteimer
|
57
20
|
#
|
58
21
|
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
59
|
-
#
|
60
|
-
|
61
22
|
|
62
23
|
require 'optparse'
|
63
24
|
require 'tempfile'
|
64
|
-
require 'fileutils'
|
65
25
|
require 'open3'
|
26
|
+
require 'erb'
|
66
27
|
|
67
28
|
# This module contains the classes for the +pdfmult+ tool.
|
68
29
|
module Pdfmult
|
69
30
|
|
70
31
|
PROGNAME = 'pdfmult'
|
71
|
-
VERSION = '1.3.
|
72
|
-
DATE = '
|
32
|
+
VERSION = '1.3.1'
|
33
|
+
DATE = '2013-01-04'
|
73
34
|
HOMEPAGE = 'https://github.com/stomar/pdfmult/'
|
35
|
+
TAGLINE = 'puts multiple copies of a PDF page on one page'
|
74
36
|
|
75
|
-
COPYRIGHT = "Copyright (C) 2011-
|
37
|
+
COPYRIGHT = "Copyright (C) 2011-2013 Marcus Stollsteimer.\n" +
|
76
38
|
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" +
|
77
39
|
"This is free software: you are free to change and redistribute it.\n" +
|
78
40
|
"There is NO WARRANTY, to the extent permitted by law."
|
@@ -126,14 +88,14 @@ module Pdfmult
|
|
126
88
|
|
127
89
|
# process --version and --help first,
|
128
90
|
# exit successfully (GNU Coding Standards)
|
129
|
-
opt.on_tail('-h', '--help', '
|
91
|
+
opt.on_tail('-h', '--help', 'Print a brief help message and exit.') do
|
130
92
|
puts opt_parser
|
131
93
|
puts "\nReport bugs on the #{PROGNAME} home page: <#{HOMEPAGE}>"
|
132
94
|
exit
|
133
95
|
end
|
134
96
|
|
135
97
|
opt.on_tail('-v', '--version',
|
136
|
-
'
|
98
|
+
'Print a brief version information and exit.') do
|
137
99
|
puts "#{PROGNAME} #{VERSION}"
|
138
100
|
puts COPYRIGHT
|
139
101
|
exit
|
@@ -173,7 +135,7 @@ module Pdfmult
|
|
173
135
|
opt_parser.parse!(argv)
|
174
136
|
|
175
137
|
# only input file should be left in argv
|
176
|
-
raise(ArgumentError, 'wrong number of arguments') if (argv.size != 1 || argv[0]
|
138
|
+
raise(ArgumentError, 'wrong number of arguments') if (argv.size != 1 || argv[0].empty?)
|
177
139
|
|
178
140
|
options[:infile] = argv.pop
|
179
141
|
|
@@ -186,6 +148,33 @@ module Pdfmult
|
|
186
148
|
end
|
187
149
|
end
|
188
150
|
|
151
|
+
# Class for the page layout.
|
152
|
+
#
|
153
|
+
# Create an instance with Layout.new, specifying
|
154
|
+
# the number of pages to put on one page.
|
155
|
+
# Layout#geometry returns the geometry string.
|
156
|
+
class Layout
|
157
|
+
|
158
|
+
attr_reader :pages, :geometry
|
159
|
+
|
160
|
+
GEOMETRY = {
|
161
|
+
2 => '2x1',
|
162
|
+
4 => '2x2',
|
163
|
+
8 => '4x2',
|
164
|
+
9 => '3x3',
|
165
|
+
16 => '4x4'
|
166
|
+
}
|
167
|
+
|
168
|
+
def initialize(pages)
|
169
|
+
@pages = pages
|
170
|
+
@geometry = GEOMETRY[pages]
|
171
|
+
end
|
172
|
+
|
173
|
+
def landscape?
|
174
|
+
['2x1', '4x2'].include?(geometry)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
189
178
|
# Class for the LaTeX document.
|
190
179
|
#
|
191
180
|
# Create an instance with LaTeXDocument.new, specifying
|
@@ -195,62 +184,50 @@ module Pdfmult
|
|
195
184
|
# The method +to_s+ returns the document as multiline string.
|
196
185
|
class LaTeXDocument
|
197
186
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
FOOTER =
|
211
|
-
"\\end{document}\n"
|
187
|
+
TEMPLATE = %q(
|
188
|
+
\documentclass[<%= class_options %>]{article}
|
189
|
+
\usepackage{pdfpages}
|
190
|
+
\pagestyle{empty}
|
191
|
+
\setlength{\parindent}{0pt}
|
192
|
+
\begin{document}
|
193
|
+
% pages_strings.each do |pages|
|
194
|
+
\includepdf[pages={<%= pages %>},nup=<%= geometry %>]{<%= @pdffile %>}%
|
195
|
+
% end
|
196
|
+
\end{document}
|
197
|
+
).gsub(/\A\n/,'').gsub(/^ +/, '')
|
212
198
|
|
213
199
|
# Initializes a LaTeXDocument instance.
|
200
|
+
# Expects an argument hash with:
|
214
201
|
#
|
215
|
-
# +
|
216
|
-
# +
|
217
|
-
#
|
218
|
-
def initialize(
|
219
|
-
@
|
220
|
-
@
|
221
|
-
@page_count = page_count
|
202
|
+
# +:pdffile+ - filename of input pdf file
|
203
|
+
# +:layout+ - page layout
|
204
|
+
# +:page_count+ - page count of the input file
|
205
|
+
def initialize(args)
|
206
|
+
@pdffile = args[:pdffile]
|
207
|
+
@layout = args[:layout]
|
208
|
+
@page_count = args[:page_count]
|
222
209
|
end
|
223
210
|
|
224
211
|
def to_s
|
225
|
-
class_options =
|
226
|
-
|
227
|
-
|
228
|
-
case @number
|
229
|
-
when 2
|
230
|
-
class_options << ',landscape'
|
231
|
-
geometry = '2x1'
|
232
|
-
when 4
|
233
|
-
geometry = '2x2'
|
234
|
-
when 8
|
235
|
-
class_options << ',landscape'
|
236
|
-
geometry = '4x2'
|
237
|
-
when 9
|
238
|
-
geometry = '3x3'
|
239
|
-
when 16
|
240
|
-
geometry = '4x4'
|
241
|
-
end
|
212
|
+
class_options = "a4paper"
|
213
|
+
class_options << ',landscape' if @layout.landscape?
|
214
|
+
latex = ERB.new(TEMPLATE, 0, '%<>')
|
242
215
|
|
243
|
-
|
244
|
-
|
245
|
-
'GEOMETRY' => geometry,
|
246
|
-
'FILENAME' => @infile)
|
216
|
+
latex.result(binding)
|
217
|
+
end
|
247
218
|
|
248
|
-
|
249
|
-
@page_count.times do |i|
|
250
|
-
content << content_template.gsub(/PAGE/,"#{i+1}")
|
251
|
-
end
|
219
|
+
private
|
252
220
|
|
253
|
-
|
221
|
+
def geometry
|
222
|
+
@layout.geometry
|
223
|
+
end
|
224
|
+
|
225
|
+
# Returns an array of pages strings.
|
226
|
+
# For 4 copies and 2 pages: ["1,1,1,1", "2,2,2,2"].
|
227
|
+
def pages_strings
|
228
|
+
template = 'PAGE,' * (@layout.pages - 1) + 'PAGE'
|
229
|
+
|
230
|
+
Array.new(@page_count) {|i| template.gsub(/PAGE/, "#{i+1}") }
|
254
231
|
end
|
255
232
|
end
|
256
233
|
|
@@ -264,31 +241,33 @@ module Pdfmult
|
|
264
241
|
|
265
242
|
PDFINFOCMD = '/usr/bin/pdfinfo'
|
266
243
|
|
267
|
-
#
|
244
|
+
# Returns the page count of the input file, or nil.
|
268
245
|
attr_reader :page_count
|
269
246
|
|
270
247
|
# This is the initialization method for the class.
|
271
248
|
#
|
272
249
|
# +file+ - file name of the PDF file
|
273
250
|
def initialize(file, options={})
|
274
|
-
@
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
251
|
+
@file = file
|
252
|
+
@binary = options[:pdfinfocmd] || PDFINFOCMD # for unit tests
|
253
|
+
@infos = retrieve_infos
|
254
|
+
@page_count = @infos['Pages'] && @infos['Pages'].to_i
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
# Tries to retrieve the PDF infos for the file; returns an info hash.
|
260
|
+
def retrieve_infos
|
261
|
+
command = "#{@binary} #{@file}"
|
262
|
+
return {} unless Application.command_available?(command)
|
263
|
+
|
264
|
+
info_array = `#{command}`.split(/\n/)
|
265
|
+
|
266
|
+
Hash[info_array.map {|line| line.split(/\s*:\s*/, 2) }]
|
288
267
|
end
|
289
268
|
|
290
269
|
# Returns true if default +pdfinfo+ system tool is available (for unit tests).
|
291
|
-
def self.infocmd_available?
|
270
|
+
def self.infocmd_available?
|
292
271
|
Application.command_available?("#{PDFINFOCMD} -v")
|
293
272
|
end
|
294
273
|
end
|
@@ -333,20 +312,19 @@ module Pdfmult
|
|
333
312
|
end
|
334
313
|
|
335
314
|
# set page number (get PDF info if necessary)
|
336
|
-
pages = options[:pages]
|
337
|
-
pages ||= PDFInfo.new(infile).page_count
|
338
|
-
pages ||= 1
|
315
|
+
pages = options[:pages] || PDFInfo.new(infile).page_count || 1
|
339
316
|
|
340
317
|
# create LaTeX document
|
341
|
-
|
318
|
+
args = {
|
319
|
+
:pdffile => infile,
|
320
|
+
:layout => Layout.new(options[:number]),
|
321
|
+
:page_count => pages
|
322
|
+
}
|
323
|
+
document = LaTeXDocument.new(args)
|
342
324
|
|
325
|
+
output = nil
|
343
326
|
if options[:latex]
|
344
|
-
|
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
|
327
|
+
output = document.to_s
|
350
328
|
else
|
351
329
|
Dir.mktmpdir('pdfmult') do |dir|
|
352
330
|
texfile = 'pdfmult.tex'
|
@@ -357,16 +335,15 @@ module Pdfmult
|
|
357
335
|
stdout.each_line {|line| warn line.chomp } unless silent # redirect progress messages to stderr
|
358
336
|
stderr.read # make sure all streams are read (and command has finished)
|
359
337
|
end
|
360
|
-
|
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)
|
367
|
-
end
|
338
|
+
output = File.read("#{dir}/#{pdffile}")
|
368
339
|
end
|
369
340
|
end
|
341
|
+
|
342
|
+
# redirect stdout to output file
|
343
|
+
$stdout.reopen(outfile, 'w') unless use_stdout
|
344
|
+
|
345
|
+
warn "Writing on #{outfile}." unless (use_stdout || silent)
|
346
|
+
puts output
|
370
347
|
end
|
371
348
|
|
372
349
|
# Asks for yes or no (y/n).
|
@@ -375,7 +352,7 @@ module Pdfmult
|
|
375
352
|
#
|
376
353
|
# Returns +true+ if the answer is yes.
|
377
354
|
def self.ask(question) # :nodoc:
|
378
|
-
|
355
|
+
loop do
|
379
356
|
$stderr.print "#{question} [y/n] "
|
380
357
|
reply = $stdin.gets.chomp.downcase # $stdin: avoids gets / ARGV problem
|
381
358
|
return true if reply == 'y'
|
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" "January 2013" "pdfmult 1.3.1" "User Commands"
|
3
3
|
.SH NAME
|
4
4
|
pdfmult \- puts multiple copies of a PDF page on one page
|
5
5
|
.SH SYNOPSIS
|
@@ -42,10 +42,10 @@ If given, pdfmult does not try to obtain the page count from the source PDF.
|
|
42
42
|
Do not output progress information.
|
43
43
|
.TP
|
44
44
|
\fB\-h\fR, \fB\-\-help\fR
|
45
|
-
|
45
|
+
Print a brief help message and exit.
|
46
46
|
.TP
|
47
47
|
\fB\-v\fR, \fB\-\-version\fR
|
48
|
-
|
48
|
+
Print a brief version information and exit.
|
49
49
|
.SH EXAMPLES
|
50
50
|
pdfmult sample.pdf # => sample_2.pdf (2 copies)
|
51
51
|
pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
@@ -55,10 +55,13 @@ Prints a brief version information and exits.
|
|
55
55
|
.SH "REPORTING BUGS"
|
56
56
|
Report bugs on the pdfmult home page: <https://github.com/stomar/pdfmult/>
|
57
57
|
.SH COPYRIGHT
|
58
|
-
Copyright \(co 2011\-
|
58
|
+
Copyright \(co 2011\-2013 Marcus Stollsteimer.
|
59
59
|
.br
|
60
60
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
61
61
|
.br
|
62
62
|
This is free software: you are free to change and redistribute it.
|
63
63
|
.br
|
64
64
|
There is NO WARRANTY, to the extent permitted by law.
|
65
|
+
.SH "SEE ALSO"
|
66
|
+
The full documentation for pdfmult is available on
|
67
|
+
the project home page: <https://github.com/stomar/pdfmult/>.
|
data/pdfmult.gemspec
CHANGED
@@ -3,6 +3,7 @@ require './lib/pdfmult'
|
|
3
3
|
version = Pdfmult::VERSION
|
4
4
|
date = Pdfmult::DATE
|
5
5
|
homepage = Pdfmult::HOMEPAGE
|
6
|
+
tagline = Pdfmult::TAGLINE
|
6
7
|
|
7
8
|
Gem::Specification.new do |s|
|
8
9
|
s.name = 'pdfmult'
|
@@ -13,7 +14,7 @@ Gem::Specification.new do |s|
|
|
13
14
|
s.description = 'pdfmult is a command line tool that rearranges ' +
|
14
15
|
'multiple copies of a PDF page (shrunken) on one page. ' +
|
15
16
|
'It is a wrapper for pdflatex with the pdfpages package.'
|
16
|
-
s.summary =
|
17
|
+
s.summary = "pdfmult - #{tagline}"
|
17
18
|
|
18
19
|
s.authors = ['Marcus Stollsteimer']
|
19
20
|
s.email = 'sto.mar@web.de'
|
data/pdfmult.h2m
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
[Name]
|
2
|
-
pdfmult \- puts multiple copies of a PDF page on one page
|
3
|
-
|
4
1
|
[Examples]
|
5
2
|
pdfmult sample.pdf # => sample_2.pdf (2 copies)
|
6
3
|
pdfmult -n 4 sample.pdf # => sample_4.pdf (4 copies)
|
7
4
|
pdfmult sample.pdf -o outfile.pdf # => outfile.pdf (2 copies)
|
8
5
|
pdfmult sample.pdf -p 3 # => processes 3 pages
|
9
6
|
pdfmult sample.pdf -o - | lpr # => sends output via stdout to print command
|
7
|
+
|
8
|
+
[See also]
|
9
|
+
The full documentation for %PROGNAME% is available on
|
10
|
+
the project home page: <%HOMEPAGE%>.
|
data/test/test_latex_document.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
1
|
# test_latex_document.rb: Unit tests for the pdfmult script.
|
3
2
|
#
|
4
|
-
# Copyright (C) 2011-
|
3
|
+
# Copyright (C) 2011-2013 Marcus Stollsteimer
|
5
4
|
|
6
5
|
require 'minitest/spec'
|
7
6
|
require 'minitest/autorun'
|
@@ -10,9 +9,31 @@ require 'pdfmult'
|
|
10
9
|
|
11
10
|
describe Pdfmult::LaTeXDocument do
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
before do
|
13
|
+
@layout_class = Pdfmult::Layout
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the expected LaTeX code for 4 pages' do
|
17
|
+
args = {
|
18
|
+
:pdffile => 'sample.pdf',
|
19
|
+
:layout => @layout_class.new(4),
|
20
|
+
:page_count => 3
|
21
|
+
}
|
22
|
+
document_lines = Pdfmult::LaTeXDocument.new(args).to_s.split(/\n/)
|
23
|
+
document_lines[0].must_equal '\documentclass[a4paper]{article}'
|
24
|
+
document_lines[-2].must_equal '\includepdf[pages={3,3,3,3},nup=2x2]{sample.pdf}%'
|
25
|
+
document_lines.grep(/includepdf/).size.must_equal args[:page_count]
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return the expected LaTeX code for 8 pages' do
|
29
|
+
args = {
|
30
|
+
:pdffile => 'sample.pdf',
|
31
|
+
:layout => @layout_class.new(8),
|
32
|
+
:page_count => 5
|
33
|
+
}
|
34
|
+
document_lines = Pdfmult::LaTeXDocument.new(args).to_s.split(/\n/)
|
35
|
+
document_lines[0].must_equal '\documentclass[a4paper,landscape]{article}'
|
36
|
+
document_lines[-2].must_equal '\includepdf[pages={5,5,5,5,5,5,5,5},nup=4x2]{sample.pdf}%'
|
37
|
+
document_lines.grep(/includepdf/).size.must_equal args[:page_count]
|
17
38
|
end
|
18
39
|
end
|
data/test/test_layout.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# test_layout.rb: Unit tests for the pdfmult script.
|
2
|
+
#
|
3
|
+
# Copyright (C) 2011-2013 Marcus Stollsteimer
|
4
|
+
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'pdfmult'
|
8
|
+
|
9
|
+
|
10
|
+
describe Pdfmult::Layout do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@layout = Pdfmult::Layout.new(2)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can return the number of pages' do
|
17
|
+
@layout.pages.must_equal 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can return the geometry' do
|
21
|
+
@layout.geometry.must_equal '2x1'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'knows whether it is landscape' do
|
25
|
+
@layout.landscape?.must_equal true
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns the correct layout for 2 pages' do
|
29
|
+
layout = Pdfmult::Layout.new(2)
|
30
|
+
layout.geometry.must_equal '2x1'
|
31
|
+
layout.landscape?.must_equal true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns the correct layout for 4 pages' do
|
35
|
+
layout = Pdfmult::Layout.new(4)
|
36
|
+
layout.geometry.must_equal '2x2'
|
37
|
+
layout.landscape?.must_equal false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the correct layout for 8 pages' do
|
41
|
+
layout = Pdfmult::Layout.new(8)
|
42
|
+
layout.geometry.must_equal '4x2'
|
43
|
+
layout.landscape?.must_equal true
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the correct layout for 9 pages' do
|
47
|
+
layout = Pdfmult::Layout.new(9)
|
48
|
+
layout.geometry.must_equal '3x3'
|
49
|
+
layout.landscape?.must_equal false
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the correct layout for 16 pages' do
|
53
|
+
layout = Pdfmult::Layout.new(16)
|
54
|
+
layout.geometry.must_equal '4x4'
|
55
|
+
layout.landscape?.must_equal false
|
56
|
+
end
|
57
|
+
end
|
data/test/test_optionparser.rb
CHANGED
data/test/test_pdfinfo.rb
CHANGED
metadata
CHANGED
@@ -1,56 +1,59 @@
|
|
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
|
+
hash: 25
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Marcus Stollsteimer
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2013-01-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
22
|
prerelease: false
|
24
|
-
|
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
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
33
24
|
none: false
|
34
|
-
requirements:
|
35
|
-
- -
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
38
32
|
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: minitest
|
39
36
|
prerelease: false
|
40
|
-
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
38
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: pdfmult is a command line tool that rearranges multiple copies of a PDF page (shrunken) on one page. It is a wrapper for pdflatex with the pdfpages package.
|
48
49
|
email: sto.mar@web.de
|
49
|
-
executables:
|
50
|
+
executables:
|
50
51
|
- pdfmult
|
51
52
|
extensions: []
|
53
|
+
|
52
54
|
extra_rdoc_files: []
|
53
|
-
|
55
|
+
|
56
|
+
files:
|
54
57
|
- README.md
|
55
58
|
- Rakefile
|
56
59
|
- pdfmult.gemspec
|
@@ -65,37 +68,44 @@ files:
|
|
65
68
|
- test/test_pdfinfo.rb
|
66
69
|
- test/test_latex_document.rb
|
67
70
|
- test/sample.tex
|
71
|
+
- test/test_layout.rb
|
68
72
|
- test/test_optionparser.rb
|
69
73
|
- test/sample.pdf
|
70
74
|
homepage: https://github.com/stomar/pdfmult/
|
71
|
-
licenses:
|
75
|
+
licenses:
|
72
76
|
- GPL-3
|
73
77
|
post_install_message:
|
74
|
-
rdoc_options:
|
78
|
+
rdoc_options:
|
75
79
|
- --charset=UTF-8
|
76
|
-
require_paths:
|
80
|
+
require_paths:
|
77
81
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
83
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
92
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements:
|
91
101
|
- pdflatex and the pdfpages package
|
92
102
|
rubyforge_project: pdfmult
|
93
103
|
rubygems_version: 1.8.24
|
94
104
|
signing_key:
|
95
105
|
specification_version: 3
|
96
106
|
summary: pdfmult - puts multiple copies of a PDF page on one page
|
97
|
-
test_files:
|
107
|
+
test_files:
|
98
108
|
- test/test_pdfinfo.rb
|
99
109
|
- test/test_latex_document.rb
|
110
|
+
- test/test_layout.rb
|
100
111
|
- test/test_optionparser.rb
|
101
|
-
has_rdoc:
|