问题
I want to print a file to the continuous paper using win32print in Python, but I have a problem in the set of the paper size .. When I following the code from: here the paper size always use A4 paper , I changed the paper size and the form name but nothing changed.
import win32print
import win32ui
import win32con
devmode.PaperSize = 50
devmode.PaperLength = 50
devmode.PaperWidth = 50
devmode.Orientation = 1
printer = win32print.GetDefaultPrinter()
hprinter = win32print.OpenPrinter(printer)
devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]
devmode.FormName = "Legal"
devmode.PaperSize = win32con.DMPAPER_9X11
devmode.PaperLength = 20
devmode.PrintQuality = 120
devmode.Orientation = 1
hDC = win32ui.CreateDC()
hDC.CreatePrinterDC(win32print.GetDefaultPrinter())
hDC.StartDoc('test')
hDC.StartPage()
scale_factor = 20
font = win32ui.CreateFont({
"name": "Monospaced",
# "name": "Times New Roman",
"height": 20,
"weight": 20,
})
hDC.SelectObject(font)
hDC.TextOut(300, 0, "TESTING ...")
hDC.EndPage()
hDC.EndDoc()
来源:https://stackoverflow.com/questions/39303945/print-file-to-continuous-paper-using-win32print-python