我希望将一些报表数据下载,抽取,切割后发送到打印机打印,因为数据横向很好,在EXCEL里可以在选择“横向”并缩放90%之后完整打印出来。
经过一个周末的学习,终于把版面横向做出来了,可是不知道为什么缩放不成功,请同学们高手们帮忙!
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=90 #这里缩放为90%
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)
作者: loolin
发布时间: 2011-07-20