25
25
"""
26
26
27
27
__author__ = 'Sergei Trofimov'
28
- __version__ = (0 , 1 , 0 )
28
+ __version__ = (0 , 1 , 1 )
29
29
30
30
import os
31
31
import sys
@@ -70,7 +70,7 @@ def scan_page(cmd, cmdopts, outdir, pageno):
70
70
args = [' ' .join (['>' , outfile ]),]
71
71
commandstring = make_command (scanimage , args , scanimage_opts )
72
72
execute_command (commandstring )
73
- return get_response ('Scan the next page?' )
73
+ return get_response ('Scan the next page ({0})?' . format ( pageno + 1 ) )
74
74
75
75
def convert_to_pdf (workdir ):
76
76
for filepath in glob (os .path .join (workdir , '*.tiff' )):
@@ -90,13 +90,31 @@ def convert_to_pdf(workdir):
90
90
91
91
def join_pdf_pages (workdir , outfile ):
92
92
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 ))
94
96
execute_command (commandstring )
95
97
logging .debug ('removing ' + tempfiles )
96
98
for f in glob (tempfiles ):
97
99
os .remove (f )
98
100
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
+
99
108
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'
100
118
workdir = mkdtemp ()
101
119
logging .debug ('using temp dir: {0}' .format (workdir ))
102
120
raw_input ('Insert the first page into the scanner and press return.' )
@@ -105,12 +123,6 @@ def join_pdf_pages(workdir, outfile):
105
123
page_count += 1
106
124
print 'Converting...'
107
125
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'
114
126
logging .debug ('writing to ' + outfile )
115
127
print 'Writing output.'
116
128
join_pdf_pages (workdir , outfile )
0 commit comments