Print To A Specific Printer With Os.startfile()
Can I print to a specific printer instead of the default printer with os.startfile(filename, 'print') I haven't found anything about the third parameter.
Solution 1:
With win32print.EnumPrinters(2) you get all the installed Printers.
This is a python 2.7 interpreter running on a windows10 machine.
import win32api
import win32print
import os
import time
import shutil
#all_printers = win32print.EnumPrinters(2)
defaultPrinter = win32print.GetDefaultPrinter()
if defaultPrinter != 'TSC TC200 UG':
win32print.SetDefaultPrinter('TSC TC200 UG')
pdf_dir = "Y:\\HOTFOLDER_DRUCK\\TSC_TC200_ETIKETTEN_UG\\INPUT"
archiv = "Y:\\HOTFOLDER_DRUCK\\TSC_TC200_ETIKETTEN_UG\\ARCHIV"while True:
files = os.listdir(pdf_dir)
if files > 0:
for f in files:
print "printing file "+ str(pdf_dir+f) +" on "+str(win32print.GetDefaultPrinter())
win32api.ShellExecute(0, "print", os.path.join(pdf_dir,f), None, ".", 0)
time.sleep(6)
shutil.copy(os.path.join(pdf_dir,f),os.path.join(archiv,f))
os.remove(os.path.join(pdf_dir,f))
Post a Comment for "Print To A Specific Printer With Os.startfile()"