pdf-page-count 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/pdf-page-count +58 -0
- data/lib/pdf-page-count.rb +3 -0
- data/lib/pdf-page-count/file_util.rb +23 -0
- data/lib/pdf-page-count/pdf_page_counter.rb +54 -0
- data/lib/pdf-page-count/pdf_util.rb +16 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c330b18c7d4a351ae47428c723c71d211088d75
|
4
|
+
data.tar.gz: a43c14003bc96f16cca3c63c8fdae14394a22c89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe2ab716f14969e39f9cca7c02b5cd555b1b55dfdf74e499600d9ee9cf505bc675dc85bb14a88bd3dd1df7d0dee24effe23da2932d94c6e0e5e7279842e91277
|
7
|
+
data.tar.gz: d9f0605f47fc199f432f07d403e30d1ec670055345f315c20a38545912a298ddf4f2486a06f043f5ec402bad124cd79ffea1efa22bcaa8b24c3c33cf1848e307
|
data/bin/pdf-page-count
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'rubygems'
|
5
|
+
require_relative '../lib/pdf-page-count'
|
6
|
+
|
7
|
+
spec = Gem::Specification::load('pdf-page-count.gemspec')
|
8
|
+
|
9
|
+
options = {
|
10
|
+
:threads => 10
|
11
|
+
}
|
12
|
+
|
13
|
+
opt_parser = OptionParser.new do |opt|
|
14
|
+
opt.banner = "Usage: pdf-page-count [options] [file/path] [file/path] ..."
|
15
|
+
opt.separator("Version: #{spec.version}")
|
16
|
+
opt.separator("")
|
17
|
+
opt.separator("Options")
|
18
|
+
|
19
|
+
opt.on("-R", "--recursive", "Recursively search for .pdf files") do
|
20
|
+
options[:recursive] = true
|
21
|
+
end
|
22
|
+
|
23
|
+
opt.on("-T", "--threads [N]", Integer, "Number of threads used to read pdf files") do |threads|
|
24
|
+
options[:threads] = threads
|
25
|
+
end
|
26
|
+
|
27
|
+
opt.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
28
|
+
options[:verbose] = v
|
29
|
+
end
|
30
|
+
|
31
|
+
opt.on("-h", "--help", "help") do
|
32
|
+
puts opt_parser
|
33
|
+
end
|
34
|
+
|
35
|
+
opt.separator("")
|
36
|
+
end
|
37
|
+
|
38
|
+
opt_parser.parse!
|
39
|
+
|
40
|
+
if ARGV.empty?
|
41
|
+
puts opt_parser
|
42
|
+
else
|
43
|
+
paths = ARGV
|
44
|
+
counter = PdfPageCount::PdfPageCounter.new
|
45
|
+
|
46
|
+
counter.start_counting(threads: options[:threads])
|
47
|
+
puts "Starting PDF page count with #{options[:threads]} threads."
|
48
|
+
|
49
|
+
counter.add_pdf_paths(paths, recursive: options[:recursive]) do |file, pages|
|
50
|
+
if options[:verbose]
|
51
|
+
puts "#{file}: #{pages}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
counter.finish_counting
|
56
|
+
|
57
|
+
puts "Total Pages: #{counter.total_pages}"
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PdfPageCount
|
2
|
+
|
3
|
+
module FileUtil
|
4
|
+
|
5
|
+
def find_pdf_files(path, recursive: false)
|
6
|
+
if File.directory?(path)
|
7
|
+
if recursive
|
8
|
+
return Dir.glob("#{path}/**/*.pdf")
|
9
|
+
else
|
10
|
+
return Dir.glob("#{path}/*.pdf")
|
11
|
+
end
|
12
|
+
elsif path.end_with?(".pdf")
|
13
|
+
return [path]
|
14
|
+
else
|
15
|
+
return []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module_function :find_pdf_files
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'thread/pool'
|
2
|
+
|
3
|
+
module PdfPageCount
|
4
|
+
|
5
|
+
class PdfPageCounter
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@total_pages = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def start_counting(threads: 10)
|
12
|
+
@process_pool = Thread.pool(threads)
|
13
|
+
@callback_pool = Thread.pool(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_pdf_paths(paths, recursive: false)
|
17
|
+
paths.each do |path|
|
18
|
+
self.add_pdf_path(path, recursive: recursive) do |file, pages|
|
19
|
+
yield file, pages
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_pdf_path(path, recursive: false)
|
25
|
+
files = FileUtil.find_pdf_files(path, recursive: recursive)
|
26
|
+
files.each do |file|
|
27
|
+
self.add_pdf_file(file) do |file, pages|
|
28
|
+
yield file, pages
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_pdf_file(file)
|
34
|
+
@process_pool.process do
|
35
|
+
pages = PdfUtil.count_pages(file)
|
36
|
+
@total_pages += pages
|
37
|
+
@callback_pool.process do
|
38
|
+
yield file, pages
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def finish_counting
|
44
|
+
@process_pool.shutdown
|
45
|
+
@callback_pool.shutdown
|
46
|
+
end
|
47
|
+
|
48
|
+
def total_pages
|
49
|
+
@total_pages
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdf-page-count
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leigh McCulloch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thread
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pdf-reader
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.3
|
41
|
+
description: Counts the pages in single and multiple PDFs. Capale of recursively finding
|
42
|
+
PDFs in directories.
|
43
|
+
email: leigh@mcchouse.com
|
44
|
+
executables:
|
45
|
+
- pdf-page-count
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/pdf-page-count
|
50
|
+
- lib/pdf-page-count.rb
|
51
|
+
- lib/pdf-page-count/file_util.rb
|
52
|
+
- lib/pdf-page-count/pdf_page_counter.rb
|
53
|
+
- lib/pdf-page-count/pdf_util.rb
|
54
|
+
homepage: http://rubygems.org/gems/pdf-page-count
|
55
|
+
licenses:
|
56
|
+
- BSD-3-Clause
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.2.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Counts the pages in single and multiple PDFs.
|
78
|
+
test_files: []
|