- 论坛徽章:
- 0
|
想把一些文本发送到打印机打印,需要改成横向,并且缩放90%。横向设置成功了,但是缩放问题竟然没解决,找不到原因,大家帮忙看看,我改成10(缩放为10%)也没效果。。。。。。
代码如下(附件中添加源文件,请将cc.rar改为cc.py打开):
import win32ui
import win32gui
import win32print
import win32con
str1 = open("D:\\b.txt","r").read()
#str1 = str1 + str1 + str1 + str1 # test height of text area
print_name =win32print.GetDefaultPrinter() # test
pHandle = win32print.OpenPrinter(win32print.GetDefaultPrinter())
printinfo = win32print.GetPrinter(pHandle,2)
pDevModeObj = printinfo["pDevMode"]
pDevModeObj.Scale=10
pDevModeObj.Orientation=win32con.DMORIENT_LANDSCAPE
print pDevModeObj.Scale
DC=win32gui.CreateDC('WINSPOOL',print_name,pDevModeObj)
hDC=win32ui.CreateDCFromHandle(DC)
hDC.StartDoc("Test doc")
hDC.StartPage()
hDC.SetMapMode(win32con.MM_TWIPS*50)
hDC.TextOut(20,20,"12345678")
#draws text within a box (assume about 1400 dots per inch for typical HP printer)
ulc_x = 1000 # give a left margin
ulc_y = -1000 # give a top margin
lrc_x = 16000 # width of text area-margin, close to right edge of page
lrc_y = -11000 # height of text area-margin, close to bottom of the page
hDC.DrawText(str1, (ulc_x, ulc_y, lrc_x, lrc_y), win32con.DT_CENTER)
hDC.EndPage()
hDC.EndDoc()
win32gui.DeleteDC(DC) |
|