PyWin32打印:指定份数

时间:2018-04-17 12:52:08

标签: python pywin32

我正在构建一个从文件夹中打印PDF文件的功能,我需要指定副本数量,实际上我是通过使用副本进行循环并将函数运行到其中来实现的。但是当打印份数很高时,打印池会饱和,从逻辑上讲,它会生成一个单独的文档来打印每个副本,而不是将打印分组到一个具有X个副本的文档中。

以下是我使用win32print打印单个文档一次的代码。 有人知道参数或选项告诉函数副本数量吗?

谢谢!

from os import path
import win32print
from win32com import client
import time
import win32api
import pywintypes
name = win32print.GetDefaultPrinter() # verify that it matches with the name of your printer
printdefaults = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS} # Doesn't work with PRINTER_ACCESS_USE
handle = win32print.OpenPrinter(name, printdefaults)
level = 2
attributes = win32print.GetPrinter(handle, level)
#attributes['pDevMode'].Duplex = 1  #no flip
#attributes['pDevMode'].Duplex = 2  #flip up
attributes['pDevMode'].Duplex = 3   #flip over
win32print.SetPrinter(handle, level, attributes, 0)
win32print.GetPrinter(handle, level)['pDevMode'].Duplex
win32api.ShellExecute(0,'print','manual1.pdf','.','/manualstoprint',0)

1 个答案:

答案 0 :(得分:0)

您是否可以选择使用Sumatra PDF?大多数命令行PDF选项可能非常有限(例如在这种情况下),但是苏门答腊的命令中有一个选项来指定类似的副本(3x意味着3个副本):

SumatraPDF -print-to-default -silent -exit-on-print -print-settings "3x" "[document location]"

当然,要做到这一点,你需要从python而不是使用win32api进行子进程调用。有关Sumatra命令行here.

的更多信息