Print file to continuous paper using win32print Python

亡梦爱人 提交于 2021-01-29 02:42:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!