Skip to content

Commit

Permalink
move to function
Browse files Browse the repository at this point in the history
  • Loading branch information
noam-arad committed Apr 3, 2017
1 parent bf825ca commit 25b0c12
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions plugins/content/document/scripts/pdfCreatorCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ def killProcessesByName(exeNames):
result = True
return result

def clearJobsQueue():
printer = win32print.OpenPrinter('PDFCreator')
jobs = win32print.EnumJobs(printer, 0, 100, 2)
while len(jobs) > 0:
for currentJob in jobs:
print '\nDeleting print job with id [' + str(currentJob['JobId']) + ']'
win32print.SetJob(printer, currentJob['JobId'], 0, None, win32print.JOB_CONTROL_DELETE)
win32print.ClosePrinter(printer)
time.sleep(.5)
printer = win32print.OpenPrinter('PDFCreator')
jobs = win32print.EnumJobs(printer, 0, 100, 2)
win32print.ClosePrinter(printer)

if len(sys.argv) < 4:
print 'wrong usage of this script. usage: %s {inputFile} {outFile} [--readOnly]' % os.path.dirname(__file__);
sys.exit(1)
Expand Down Expand Up @@ -119,21 +132,11 @@ def killProcessesByName(exeNames):
else:
commandParams.append('/PF"%s"' % inputFile)


printer = win32print.OpenPrinter('PDFCreator')

#make sure print queue is empty, if not delete existing jobs.
jobs = win32print.EnumJobs(printer, 0, 100, 2)
while len(jobs) > 0:
for currentJob in jobs:
print '\nDeleting print job with id [' + str(currentJob['JobId']) + ']'
win32print.SetJob(printer, currentJob['JobId'], 0, None, win32print.JOB_CONTROL_DELETE)
win32print.ClosePrinter(printer)
time.sleep(.5)
printer = win32print.OpenPrinter('PDFCreator')
jobs = win32print.EnumJobs(printer, 0, 100, 2)
clearJobsQueue()

command = ' '.join(commandParams)
printer = win32print.OpenPrinter('PDFCreator')
command = ' '.join(commandParams)

# execute the command
print '\ncommand: %s' % command
Expand Down

0 comments on commit 25b0c12

Please sign in to comment.