Skip to content

Commit bd02f0f

Browse files
committed
Added/fixed some stuff.
1 parent 0a5e6d5 commit bd02f0f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

scandocument.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
__author__ = 'Sergei Trofimov'
28-
__version__ = (0, 1, 0)
28+
__version__ = (0, 1, 1)
2929

3030
import os
3131
import sys
@@ -70,7 +70,7 @@ def scan_page(cmd, cmdopts, outdir, pageno):
7070
args = [' '.join(['>', outfile]),]
7171
commandstring = make_command(scanimage, args, scanimage_opts)
7272
execute_command(commandstring)
73-
return get_response('Scan the next page?')
73+
return get_response('Scan the next page ({0})?'.format(pageno+1))
7474

7575
def convert_to_pdf(workdir):
7676
for filepath in glob(os.path.join(workdir, '*.tiff')):
@@ -90,13 +90,31 @@ def convert_to_pdf(workdir):
9090

9191
def join_pdf_pages(workdir, outfile):
9292
tempfiles = os.path.join(workdir, '*.pdf')
93-
commandstring = '{0} {1} -o \'{2}\''.format(pdfjoin, ' '.join(glob(tempfiles)), outfile)
93+
commandstring = '{0} {1} -o "{2}"'.format(pdfjoin,
94+
' '.join(glob(tempfiles)),
95+
os.path.expanduser(outfile))
9496
execute_command(commandstring)
9597
logging.debug('removing ' + tempfiles)
9698
for f in glob(tempfiles):
9799
os.remove(f)
98100

101+
def print_help():
102+
print 'python scandocument.py [OUTFILE]'
103+
print
104+
print 'Scan a multi-page document into a .pdf file (OUTFILE).'
105+
print 'If OUTFILE isn\'t specifified, it will be read from STDIN.'
106+
print
107+
99108
if __name__ == '__main__':
109+
if len(sys.argv) > 1:
110+
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
111+
print_help()
112+
sys.exit(0)
113+
outfile = sys.argv[1]
114+
else:
115+
outfile = raw_input('Please specify output file: ')
116+
if not outfile.lower().endswith('.pdf'):
117+
outfile += '.pdf'
100118
workdir = mkdtemp()
101119
logging.debug('using temp dir: {0}'.format(workdir))
102120
raw_input('Insert the first page into the scanner and press return.')
@@ -105,12 +123,6 @@ def join_pdf_pages(workdir, outfile):
105123
page_count += 1
106124
print 'Converting...'
107125
convert_to_pdf(workdir)
108-
if len(sys.argv) > 1:
109-
outfile = sys.argv[1]
110-
else:
111-
outfile = raw_input('Please specify output file: ')
112-
if not outfile.lower().endswith('.pdf'):
113-
outfile += '.pdf'
114126
logging.debug('writing to ' + outfile)
115127
print 'Writing output.'
116128
join_pdf_pages(workdir, outfile)

0 commit comments

Comments
 (0)