我已经创建了一个Windows应用程序,并连接了打印功能的按钮,我可以设置纸张大小,但问题是我不能写任何东西。
scale_factor = 20
# Get a handle for the default printer
device_name = win32print.GetDefaultPrinter()
handle = win32print.OpenPrinter(device_name)
# Get the default properties for the printer
properties = win32print.GetPrinter(handle, 2)
devmode = properties['pDevMode']
devmode.PaperSize=win32con.DMPAPER_B5
# Start printing with the device
hdc = win32gui.CreateDC('Hello ', device_name, devmode)
win32print.StartDoc(hdc,('Hello',None, None, 0))
win32print.StartPage(hdc)
pen = win32gui.CreatePen(0, int(scale_factor),0)
win32gui.SelectObject(hdc,pen)
win32gui.ExtTextOut(hdc,scale_factor * 72,-1 * scale_factor * 72,1,None,"Testing..")
win32print.EndPage(hdc)
win32print.EndDoc(hdc)
1条答案
按热度按时间hmmo2u0o1#
我的代码的问题是比例因子(-1)。还可以尝试使用ExtTextOut()和DrawText(),
函数http://timgolden.me.uk/pywin32-docs/win32gui__ExtTextOut_meth.htmlhttp://timgolden.me.uk/pywin32-docs/win32gui__DrawText_meth.html的参考