Python win32print改变了高级打印机选项

时间:2011-04-05 16:51:18

标签: python winapi

我正在使用python 2.7和win32print。我可以成功地改变肖像和风景之间的方向:

PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ALL_ACCESS}  
pHandle = win32print.OpenPrinter('300LN1', PRINTER_DEFAULTS)  
properties = win32print.GetPrinter(pHandle, 2)  
pDevModeObj.Orientation = 2  
properties["pDevMode"]=pDevModeObj   
win32print.SetPrinter(pHandle,2,properties,0) 

但是,我想更改打印机的某些自定义属性,但似乎无法找到执行此操作的位置。这是我想要更改的标签之一:http://dl.dropbox.com/u/584330/print.jpg。我相信当启用“高级打印功能选项”时,可以访问这些选项。

其他信息(代码):

devmode=pDevModeObj  
for n in dir(devmode):  
  print "%s\t%s" % (n,getattr(devmode,n))  

输出:

BitsPerPel  0
Clear   <built-in method Clear of PyDEVMODEA object at 0x028EE750>
Collate 1
Color   2
Copies  1
DefaultSource   15
DeviceName  300LN1
DisplayFixedOutput  19660815
DisplayFlags    1
DisplayFrequency    0
DisplayOrientation  65636
DitherType  4294967295
DriverData  DINU"    DriverExtra    824
DriverVersion   1536
Duplex  1
Fields  92401475
FormName    Letter
ICMIntent   2
ICMMethod   1
LogPixels   0
MediaType   1
Nup 1
Orientation 2
PanningHeight   0
PanningWidth    0
PaperLength 2794
PaperSize   1
PaperWidth  2159
PelsHeight  0
PelsWidth   0
Position_x  65538
Position_y  141495018
PrintQuality    300
Reserved1   0
Reserved2   0
Scale   100
Size    156
SpecVersion 1025
TTOption    2
YResolution 300
__class__   <type 'PyDEVMODEA'>
__delattr__ <method-wrapper '__delattr__' of PyDEVMODEA object at 0x028EE750>
__doc__ None
__format__  <built-in method __format__ of PyDEVMODEA object at 0x028EE750>
__getattribute__    <method-wrapper '__getattribute__' of PyDEVMODEA object at 0x028EE750>
__hash__    <method-wrapper '__hash__' of PyDEVMODEA object at 0x028EE750>
__init__    <method-wrapper '__init__' of PyDEVMODEA object at 0x028EE750>
__new__ <built-in method __new__ of type object at 0x1E7B9970>
__reduce__  <built-in method __reduce__ of PyDEVMODEA object at 0x028EE750>
__reduce_ex__   <built-in method __reduce_ex__ of PyDEVMODEA object at 0x028EE750>
__repr__    <method-wrapper '__repr__' of PyDEVMODEA object at 0x028EE750>
__setattr__ <method-wrapper '__setattr__' of PyDEVMODEA object at 0x028EE750>
__sizeof__  <built-in method __sizeof__ of PyDEVMODEA object at 0x028EE750>
__str__ <method-wrapper '__str__' of PyDEVMODEA object at 0x028EE750>
__subclasshook__    <built-in method __subclasshook__ of type object at 0x1E7B9970>

[edit]我刚试过以下代码:

win32print.DocumentProperties(0, pHandle, '300LN1', None, None, 5)

这会弹出我想要修改的属性窗口。

另外,你知道是否有可能要求打印机一旦打到300页就停止打印?

1 个答案:

答案 0 :(得分:0)

from ctypes import windll
windll['winspool.drv'].AdvancedDocumentPropertiesA(None, pHandle.handle, '300LN1', None, None)