我目前正在编写一个脚本,该脚本将根据我的要求裁剪 PDF 文件并将它们合并到一个 pdf 文件中。这应在之后通过默认打印机直接打印,但使用侧面打印机托盘并以 A6 格式打印。因此,我希望脚本在打印之前打开打印机属性对话框窗口。
我很感激任何帮助,因为我已经在互联网上搜索了无数小时
我目前正在编写一个脚本,该脚本将根据我的要求裁剪 PDF 文件并将它们合并到一个 pdf 文件中。这应在之后通过默认打印机直接打印,但使用侧面打印机托盘并以 A6 格式打印。因此,我希望脚本在打印之前打开打印机属性对话框窗口。
我很感激任何帮助,因为我已经在互联网上搜索了无数小时
我终于找到了解决方案。希望这也可以帮助您/您正在寻找什么。
import win32print
name="printername"
# access defaults
PRINTER_DEFAULTS = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS}
# open printer to get the handle
pHandle = win32print.OpenPrinter(name,PRINTER_DEFAULTS)
# get the current properties
properties = win32print.GetPrinter(pHandle, 2)
#get the devmode
pDevModeObj = properties['pDevMode']
#open the printer properties and pass the devmode
win32print.DocumentProperties(0, pHandle, name, pDevModeObj, None, 5)
# reassign the devmode
properties['pDevMode'] = pDevModeObj
# save the printer settings
win32print.SetPrinter(pHandle,2,properties,0)
# close the printer
win32print.ClosePrinter(pHandle)