-
Notifications
You must be signed in to change notification settings - Fork 1
/
redact.rb
executable file
·47 lines (37 loc) · 1.22 KB
/
redact.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env jruby -J-Djava.awt.headless=true
# encoding: utf-8
require 'trollop'
require_relative 'lib/pdfbox'
require_relative 'lib/ssn-redaction/ssn-redaction'
def parse_command_line
opts = Trollop::options do
version "pdfredaction #{PDFRedaction::VERSION} #OWS Hackaton 2014"
banner <<-EOS
PDF Redaction helps you redact SSN from PDFs
Usage:
redact [options] <pdf_file>
where [options] are:
EOS
opt :password, 'Password to decrypt document. Default is empty', :default => ''
opt :silent, 'Suppress all stderr output.'
opt :test, 'Print amount of matches per page.'
end
Trollop::die "need one filename" if ARGV.empty?
pdf_filename = ARGV.shift
Trollop::die 'file does not exist' unless File.exists? pdf_filename
return opts, pdf_filename
end
def main
opts, filename = parse_command_line
if opts[:test]
amount_matches = SSNRedaction::count_matches(filename)
amount_matches[:pages].keys.each do |page_number|
puts "Page #{page_number}: #{amount_matches[:pages][page_number].length} matches."
amount_matches[:pages][page_number].each do |chunk|
puts chunk.text
end
end
print "Total: %s" % amount_matches[:total]
end
end
main