pdfmult 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9bf2768201410416ee2153db93969369d244400
4
+ data.tar.gz: 9d557ec2a86736e344a32f74429444284c669215
5
+ SHA512:
6
+ metadata.gz: a28230d86378317f8f9a1a4f840337db503a0a8858d76aed997c39d1eebfd0d353118dbd304f6ecde108adb79bb61c50ab093f3b08285376d8fdada93f576fda
7
+ data.tar.gz: 3144c04883b80892b335add20689d04cc85a5b500a9499989b5db282e6bcb02f3091e4915e5599b71b47ffb8f98c39e82c8747e0739547f6fc56a9d2752c2d69
data/README.md CHANGED
@@ -23,13 +23,13 @@ Use the program as shown in the examples below.
23
23
 
24
24
  writes 2 copies of `sample.pdf` to `sample_2.pdf`
25
25
 
26
- <img src="https://github.com/stomar/pdfmult/raw/master/example1.png" alt="" width="152" height="59">
26
+ <img src="example1.png" alt="" width="152" height="59">
27
27
 
28
28
  * `pdfmult -n 4 sample.pdf`
29
29
 
30
30
  writes 4 copies of `sample.pdf` to `sample_4.pdf`
31
31
 
32
- <img src="https://github.com/stomar/pdfmult/raw/master/example2.png" alt="" width="234" height="59">
32
+ <img src="example2.png" alt="" width="234" height="59">
33
33
 
34
34
  * `pdfmult sample.pdf -o outfile.pdf`
35
35
 
@@ -46,7 +46,7 @@ Use the program as shown in the examples below.
46
46
  Installation
47
47
  ------------
48
48
 
49
- Use `gem install pdfmult`.
49
+ Use `gem install pdfmult` to install from RubyGems.org.
50
50
 
51
51
  Or copy `lib/pdfmult.rb` under the name `pdfmult` into your search path.
52
52
 
@@ -60,7 +60,7 @@ As of now, `pdfmult` has only been tested on a Linux system.
60
60
 
61
61
  - `pdfmult` is written in [Ruby][Ruby], so Ruby must be installed on your system.
62
62
  - `pdfmult` uses `pdflatex` with the `pdfpages` package, so both have to be installed on the system.
63
- (If `pdfmult` can not find the `pdflatex` command on your system
63
+ (If `pdfmult` cannot find the `pdflatex` command on your system
64
64
  you might want to use the `--latex` option.)
65
65
  - `pdfmult` tries to obtain the page count of PDF files with `pdfinfo`.
66
66
  If it fails, by default only the first page of a PDF file will be processed.
@@ -81,7 +81,7 @@ Report bugs on the `pdfmult` home page: <https://github.com/stomar/pdfmult/>
81
81
  License
82
82
  -------
83
83
 
84
- Copyright &copy; 2011-2012, Marcus Stollsteimer
84
+ Copyright &copy; 2011-2013 Marcus Stollsteimer
85
85
 
86
86
  `pdfmult` is free software: you can redistribute it and/or modify
87
87
  it under the terms of the GNU General Public License version 3 or later (GPLv3+),
data/bin/pdfmult CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'pdfmult'
4
4
 
5
- Pdfmult::Application.run!
5
+ Pdfmult::Application.new.run!
data/lib/pdfmult.rb CHANGED
@@ -29,15 +29,17 @@ require 'erb'
29
29
  module Pdfmult
30
30
 
31
31
  PROGNAME = 'pdfmult'
32
- VERSION = '1.3.1'
33
- DATE = '2013-01-04'
32
+ VERSION = '1.3.2'
33
+ DATE = '2013-10-27'
34
34
  HOMEPAGE = 'https://github.com/stomar/pdfmult/'
35
35
  TAGLINE = 'puts multiple copies of a PDF page on one page'
36
36
 
37
- COPYRIGHT = "Copyright (C) 2011-2013 Marcus Stollsteimer.\n" +
38
- "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" +
39
- "This is free software: you are free to change and redistribute it.\n" +
40
- "There is NO WARRANTY, to the extent permitted by law."
37
+ COPYRIGHT = <<-copyright.gsub(/^ +/, '')
38
+ Copyright (C) 2011-2013 Marcus Stollsteimer.
39
+ License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
40
+ This is free software: you are free to change and redistribute it.
41
+ There is NO WARRANTY, to the extent permitted by law.
42
+ copyright
41
43
 
42
44
  PDFLATEX = '/usr/bin/pdflatex'
43
45
  KPSEWHICH = '/usr/bin/kpsewhich'
@@ -67,24 +69,24 @@ module Pdfmult
67
69
 
68
70
  opt_parser = OptionParser.new do |opt|
69
71
  opt.banner = "Usage: #{PROGNAME} [options] file"
70
- opt.separator ''
71
- opt.separator 'pdfmult is a command line tool that'
72
- opt.separator 'rearranges multiple copies of a PDF page (shrunken) on one page.'
73
- opt.separator ''
74
- opt.separator 'The paper size of the produced PDF file is A4,'
75
- opt.separator 'the input file is also assumed to be in A4 format.'
76
- opt.separator 'The input PDF file may consist of several pages.'
77
- opt.separator 'If pdfmult succeeds in obtaining the page count it will rearrange all pages,'
78
- opt.separator 'if not, only the first page is processed'
79
- opt.separator '(unless the page count was specified via command line option).'
80
- opt.separator ''
81
- opt.separator 'pdfmult uses pdflatex with the pdfpages package,'
82
- opt.separator 'so both have to be installed on the system.'
83
- opt.separator 'If the --latex option is used, though, pdflatex is not run'
84
- opt.separator 'and a LaTeX file is created instead of a PDF.'
85
- opt.separator ''
86
- opt.separator 'Options'
87
- opt.separator ''
72
+ opt.separator %q{
73
+ pdfmult is a command line tool that
74
+ rearranges multiple copies of a PDF page (shrunken) on one page.
75
+
76
+ The paper size of the produced PDF file is A4,
77
+ the input file is also assumed to be in A4 format.
78
+ The input PDF file may consist of several pages.
79
+ If pdfmult succeeds in obtaining the page count it will rearrange all pages,
80
+ if not, only the first page is processed
81
+ (unless the page count was specified via command line option).
82
+
83
+ pdfmult uses pdflatex with the pdfpages package,
84
+ so both have to be installed on the system.
85
+ If the --latex option is used, though, pdflatex is not run
86
+ and a LaTeX file is created instead of a PDF.
87
+
88
+ Options
89
+ }.gsub(/^ +/, '')
88
90
 
89
91
  # process --version and --help first,
90
92
  # exit successfully (GNU Coding Standards)
@@ -177,13 +179,14 @@ module Pdfmult
177
179
 
178
180
  # Class for the LaTeX document.
179
181
  #
180
- # Create an instance with LaTeXDocument.new, specifying
181
- # the input file, the number of pages to put on one page,
182
- # and the page count of the input file.
182
+ # Create an instance with LaTeXDocument.new, specifying the
183
+ # input file, the layout, and the page count of the input file.
183
184
  #
184
185
  # The method +to_s+ returns the document as multiline string.
185
186
  class LaTeXDocument
186
187
 
188
+ attr_reader :pdffile, :layout, :page_count
189
+
187
190
  TEMPLATE = %q(
188
191
  \documentclass[<%= class_options %>]{article}
189
192
  \usepackage{pdfpages}
@@ -191,7 +194,7 @@ module Pdfmult
191
194
  \setlength{\parindent}{0pt}
192
195
  \begin{document}
193
196
  % pages_strings.each do |pages|
194
- \includepdf[pages={<%= pages %>},nup=<%= geometry %>]{<%= @pdffile %>}%
197
+ \includepdf[pages={<%= pages %>},nup=<%= geometry %>]{<%= pdffile %>}%
195
198
  % end
196
199
  \end{document}
197
200
  ).gsub(/\A\n/,'').gsub(/^ +/, '')
@@ -209,8 +212,8 @@ module Pdfmult
209
212
  end
210
213
 
211
214
  def to_s
212
- class_options = "a4paper"
213
- class_options << ',landscape' if @layout.landscape?
215
+ class_options = 'a4paper'
216
+ class_options << ',landscape' if layout.landscape?
214
217
  latex = ERB.new(TEMPLATE, 0, '%<>')
215
218
 
216
219
  latex.result(binding)
@@ -219,15 +222,19 @@ module Pdfmult
219
222
  private
220
223
 
221
224
  def geometry
222
- @layout.geometry
225
+ layout.geometry
226
+ end
227
+
228
+ def pages_per_sheet
229
+ layout.pages
223
230
  end
224
231
 
225
232
  # Returns an array of pages strings.
226
233
  # For 4 copies and 2 pages: ["1,1,1,1", "2,2,2,2"].
227
234
  def pages_strings
228
- template = 'PAGE,' * (@layout.pages - 1) + 'PAGE'
235
+ pages = (1..page_count).to_a
229
236
 
230
- Array.new(@page_count) {|i| template.gsub(/PAGE/, "#{i+1}") }
237
+ pages.map {|page| ([page] * pages_per_sheet).join(',') }
231
238
  end
232
239
  end
233
240
 
@@ -250,8 +257,8 @@ module Pdfmult
250
257
  def initialize(file, options={})
251
258
  @file = file
252
259
  @binary = options[:pdfinfocmd] || PDFINFOCMD # for unit tests
253
- @infos = retrieve_infos
254
- @page_count = @infos['Pages'] && @infos['Pages'].to_i
260
+ infos = retrieve_infos
261
+ @page_count = infos['Pages'] && infos['Pages'].to_i
255
262
  end
256
263
 
257
264
  private
@@ -279,51 +286,52 @@ module Pdfmult
279
286
 
280
287
  ERRORCODE = {:general => 1, :usage => 2}
281
288
 
282
- # The main program.
283
- def self.run!
284
-
285
- # parse options
289
+ def initialize
286
290
  begin
287
291
  options = Optionparser.parse!(ARGV)
288
292
  rescue => e
289
293
  usage_fail(e.message)
290
294
  end
295
+ @infile = options[:infile]
296
+ @outfile = options[:outfile]
297
+ @use_stdout = (@outfile == '-')
298
+ @silent = options[:silent]
299
+ @force = options[:force]
300
+ @latex = options[:latex]
301
+ @number = options[:number]
302
+ @pages = options[:pages] || PDFInfo.new(@infile).page_count || 1
303
+ end
291
304
 
292
- infile = options[:infile]
293
- outfile = options[:outfile]
294
- use_stdout = (outfile == '-')
295
- silent = options[:silent]
305
+ # The main program.
306
+ def run!
296
307
 
297
308
  # test for pdflatex installation
298
- unless options[:latex]
309
+ unless @latex
299
310
  message = 'seems not to be installed (you might try using the -l option)'
300
- general_fail("`#{PDFLATEX}' #{message}") unless command_available?("#{PDFLATEX} --version")
301
- general_fail("`pdfpages.sty' #{message}") unless command_available?("#{KPSEWHICH} pdfpages.sty")
311
+ general_fail("`#{PDFLATEX}' #{message}") unless self.class.command_available?("#{PDFLATEX} --version")
312
+ general_fail("`pdfpages.sty' #{message}") unless self.class.command_available?("#{KPSEWHICH} pdfpages.sty")
302
313
  end
303
314
 
304
315
  # test input file
305
- usage_fail("no such file: `#{infile}'") unless File.exist?(infile)
306
- usage_fail("specified input not of the type `file'") unless File.ftype(infile) == 'file'
316
+ usage_fail("no such file: `#{@infile}'") unless File.exist?(@infile)
317
+ usage_fail("specified input not of the type `file'") unless File.ftype(@infile) == 'file'
307
318
 
308
319
  # test for existing output file
309
- if !use_stdout and !options[:force] and File.exist?(outfile)
310
- overwrite_ok = ask("File `#{outfile}' already exists. Overwrite?")
320
+ if !@use_stdout && !@force && File.exist?(@outfile)
321
+ overwrite_ok = confirm("File `#{@outfile}' already exists. Overwrite?")
311
322
  exit unless overwrite_ok
312
323
  end
313
324
 
314
- # set page number (get PDF info if necessary)
315
- pages = options[:pages] || PDFInfo.new(infile).page_count || 1
316
-
317
325
  # create LaTeX document
318
326
  args = {
319
- :pdffile => infile,
320
- :layout => Layout.new(options[:number]),
321
- :page_count => pages
327
+ :pdffile => @infile,
328
+ :layout => Layout.new(@number),
329
+ :page_count => @pages
322
330
  }
323
331
  document = LaTeXDocument.new(args)
324
332
 
325
333
  output = nil
326
- if options[:latex]
334
+ if @latex
327
335
  output = document.to_s
328
336
  else
329
337
  Dir.mktmpdir('pdfmult') do |dir|
@@ -332,7 +340,7 @@ module Pdfmult
332
340
  open("#{dir}/#{texfile}", 'w') {|f| f.write(document.to_s) }
333
341
  command = "#{PDFLATEX} -output-directory #{dir} #{texfile}"
334
342
  Open3.popen3(command) do |stdin, stdout, stderr|
335
- stdout.each_line {|line| warn line.chomp } unless silent # redirect progress messages to stderr
343
+ stdout.each_line {|line| warn line.chomp } unless @silent # redirect progress messages to stderr
336
344
  stderr.read # make sure all streams are read (and command has finished)
337
345
  end
338
346
  output = File.read("#{dir}/#{pdffile}")
@@ -340,35 +348,36 @@ module Pdfmult
340
348
  end
341
349
 
342
350
  # redirect stdout to output file
343
- $stdout.reopen(outfile, 'w') unless use_stdout
351
+ $stdout.reopen(@outfile, 'w') unless @use_stdout
344
352
 
345
- warn "Writing on #{outfile}." unless (use_stdout || silent)
353
+ warn "Writing on #{@outfile}." unless (@use_stdout || @silent)
346
354
  puts output
347
355
  end
348
356
 
357
+ private
358
+
349
359
  # Asks for yes or no (y/n).
350
360
  #
351
361
  # +question+ - string to be printed
352
362
  #
353
363
  # Returns +true+ if the answer is yes.
354
- def self.ask(question) # :nodoc:
364
+ def confirm(question)
355
365
  loop do
356
366
  $stderr.print "#{question} [y/n] "
357
- reply = $stdin.gets.chomp.downcase # $stdin: avoids gets / ARGV problem
358
- return true if reply == 'y'
359
- return false if reply == 'n'
367
+ reply = $stdin.gets.chomp.downcase # $stdin avoids gets/ARGV problem
368
+ return reply == 'y' if /\A[yn]\Z/ =~ reply
360
369
  warn "Please answer `y' or `n'."
361
370
  end
362
371
  end
363
372
 
364
373
  # Prints an error message and exits.
365
- def self.general_fail(message) # :nodoc:
374
+ def general_fail(message)
366
375
  warn "#{PROGNAME}: #{message}"
367
376
  exit ERRORCODE[:general]
368
377
  end
369
378
 
370
379
  # Prints an error message and a short help information, then exits.
371
- def self.usage_fail(message) # :nodoc:
380
+ def usage_fail(message)
372
381
  warn "#{PROGNAME}: #{message}"
373
382
  warn "Use `#{PROGNAME} --help' for valid options."
374
383
  exit ERRORCODE[:usage]
@@ -381,11 +390,10 @@ module Pdfmult
381
390
  !!system("#{command} >/dev/null 2>&1")
382
391
  end
383
392
  end
393
+ end # module
384
394
 
385
395
  ### call main method only if called on command line
386
396
 
387
397
  if __FILE__ == $0
388
- Application.run!
398
+ Pdfmult::Application.new.run!
389
399
  end
390
-
391
- end # module
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" "January 2013" "pdfmult 1.3.1" "User Commands"
2
+ .TH PDFMULT "1" "October 2013" "pdfmult 1.3.2" "User Commands"
3
3
  .SH NAME
4
4
  pdfmult \- puts multiple copies of a PDF page on one page
5
5
  .SH SYNOPSIS
data/pdfmult.gemspec CHANGED
@@ -9,7 +9,6 @@ Gem::Specification.new do |s|
9
9
  s.name = 'pdfmult'
10
10
  s.version = version
11
11
  s.date = date
12
- s.rubyforge_project = 'pdfmult'
13
12
 
14
13
  s.description = 'pdfmult is a command line tool that rearranges ' +
15
14
  'multiple copies of a PDF page (shrunken) on one page. ' +
@@ -24,12 +23,15 @@ Gem::Specification.new do |s|
24
23
 
25
24
  s.requirements << 'pdflatex and the pdfpages package'
26
25
 
26
+ s.add_development_dependency('rake')
27
+ s.add_development_dependency('minitest')
28
+
27
29
  s.executables = ['pdfmult']
28
30
  s.bindir = 'bin'
31
+
29
32
  s.require_path = 'lib'
30
- s.test_files = Dir.glob('test/**/test_*.rb')
31
33
 
32
- s.rdoc_options = ['--charset=UTF-8']
34
+ s.test_files = Dir.glob('test/**/test_*.rb')
33
35
 
34
36
  s.files = %w{
35
37
  README.md
@@ -40,6 +42,5 @@ Gem::Specification.new do |s|
40
42
  Dir.glob('example*.*') +
41
43
  Dir.glob('{bin,lib,man,test}/**/*')
42
44
 
43
- s.add_development_dependency('rake')
44
- s.add_development_dependency('minitest')
45
+ s.rdoc_options = ['--charset=UTF-8']
45
46
  end
metadata CHANGED
@@ -1,59 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pdfmult
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 1
8
- - 3
9
- - 1
10
- version: 1.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.2
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Marcus Stollsteimer
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-01-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: minitest
36
21
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  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.
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: pdfmult is a command line tool that rearranges multiple copies of a PDF
42
+ page (shrunken) on one page. It is a wrapper for pdflatex with the pdfpages package.
49
43
  email: sto.mar@web.de
50
- executables:
44
+ executables:
51
45
  - pdfmult
52
46
  extensions: []
53
-
54
47
  extra_rdoc_files: []
55
-
56
- files:
48
+ files:
57
49
  - README.md
58
50
  - Rakefile
59
51
  - pdfmult.gemspec
@@ -72,39 +64,32 @@ files:
72
64
  - test/test_optionparser.rb
73
65
  - test/sample.pdf
74
66
  homepage: https://github.com/stomar/pdfmult/
75
- licenses:
67
+ licenses:
76
68
  - GPL-3
69
+ metadata: {}
77
70
  post_install_message:
78
- rdoc_options:
71
+ rdoc_options:
79
72
  - --charset=UTF-8
80
- require_paths:
73
+ require_paths:
81
74
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
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
92
- none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 0
99
- version: "0"
100
- requirements:
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements:
101
86
  - pdflatex and the pdfpages package
102
- rubyforge_project: pdfmult
103
- rubygems_version: 1.8.24
87
+ rubyforge_project:
88
+ rubygems_version: 2.1.9
104
89
  signing_key:
105
- specification_version: 3
90
+ specification_version: 4
106
91
  summary: pdfmult - puts multiple copies of a PDF page on one page
107
- test_files:
92
+ test_files:
108
93
  - test/test_pdfinfo.rb
109
94
  - test/test_latex_document.rb
110
95
  - test/test_layout.rb