python pywin32控制打印机
时间:2011-07-19
来源:互联网
想把一些文本发送到打印机打印,需要改成横向,并且缩放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)
代码如下(附件中添加源文件,请将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)
作者: soarnil 发布时间: 2011-07-19
竟然没一个人回应?啥也不说了~~~~
作者: soarnil 发布时间: 2011-07-20
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28