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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
from win32print import *
class DriverPrinter():
'''
Manage print
'''
def __init__(self, printer, color_option):
'''
Constructor
'''
# Printer as a string
self.printer = printer
# Color Options
self.color_option = color_option
# Queue as private variable / FIFO
self.__queue = []
def enqueueFile(self, file):
'''
Add one file to queue
@param file: a new file
'''
self.__queue.append(file)
def cancelNextFile(self):
'''
Pops 1st file
'''
if len(self.__queue) > 0:
self.__queue.pop()
def getQueue(self):
'''
Returns the queue
@return: the queue of files to print
'''
return self.__queue
def runPrint(self):
'''
Run the printer for all the files enqueued
'''
#print(GetDefaultPrinter())
#print "Imprimante sélectionnée : " + self.printer
for ep in EnumPrinters(4):
if ( self.printer == ep[2] ):
handlerP = OpenPrinter(ep[2])
break
print (GetDefaultPrinter())
printerSettings = GetPrinter(handlerP, 2)
print(printerSettings)
printerSettings["pPrinterName"] = self.printer
SetPrinter(handlerP, 2, printerSettings, 0)
for f in self.getQueue():
StartDocPrinter(f)
if __name__ == "__main__":
dp = DriverPrinter(printer=r"\\tomate\Copieur Toulouse", color_option="yes")
dp.enqueueFile(r"C:/exemple.pdf")
dp.runPrint() |