【问题标题】:Print a PDF File in Python but show the printer properties dialog window before using python在 Python 中打印 PDF 文件,但在使用 python 之前显示打印机属性对话框窗口
【发布时间】:2021-08-27 06:12:39
【问题描述】:

我目前正在编写一个脚本,该脚本将根据我的要求裁剪 PDF 文件并将它们合并到一个 pdf 文件中。这应在之后通过默认打印机直接打印,但使用侧面打印机托盘并以 A6 格式打印。因此,我希望脚本在打印之前打开打印机属性对话框窗口。

I am talking about this dialog window

感谢您的帮助,因为我已经在互联网上搜索了无数小时

【问题讨论】:

  • 您找到解决方案了吗?几个月来,我一直在寻找打开此对话框的好方法。我能做的就是打开它,但它经常崩溃。
  • @Coretaxxe 我在 Windows 控制中心创建了我现有打印机的副本,并在那里输入了我所需的设置作为默认值(通过辅助打印机托盘进行黑白 DIN A6 打印)。然后我按照here 的描述使用 Ghostscript,此时打印的结果看起来不正确。我不得不在 python code 中添加一些参数
  • 非常感谢!

标签: python pdf printing printer-properties


【解决方案1】:

我终于找到了解决办法。希望这也能帮助您/正是您想要的。

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    相关资源
    最近更新 更多