我想在Python中使用win32print将文件打印到连续纸上,但我在纸张大小的设置中有问题。 当我关注以下代码时:here 纸张尺寸总是使用A4纸,我更改了纸张尺寸和表格名称,但没有改变。
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()