Python print pdf file with win32print

后端 未结 3 761
礼貌的吻别
礼貌的吻别 2021-01-11 23:28

I\'m trying to print a pdf file from Python with module win32print but the only way I can print success is a text.

hPrinter = win32print.OpenPri         


        
3条回答
  •  伪装坚强ぢ
    2021-01-11 23:55

    This is the code I have used and it works correctly.

    name = win32print.GetDefaultPrinter() # verify that it matches with the name of your printer
    printdefaults = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS} # Doesn't work with PRINTER_ACCESS_USE
    handle = win32print.OpenPrinter(name, printdefaults)
    level = 2
    attributes = win32print.GetPrinter(handle, level)
    #attributes['pDevMode'].Duplex = 1  #no flip
    #attributes['pDevMode'].Duplex = 2  #flip up
    attributes['pDevMode'].Duplex = 3   #flip over
    win32print.SetPrinter(handle, level, attributes, 0)
    win32print.GetPrinter(handle, level)['pDevMode'].Duplex
    win32api.ShellExecute(0,'print','manual1.pdf','.','/manualstoprint',0)
    

提交回复
热议问题