我正在尝试使用 Python 打印 PDF,而不打开 PDF 查看器应用程序(Adobe、Foxit 等)。我还需要知道打印何时完成(删除文件)。
在这里我找到了这个实现:
import win32ui, dde, os.path, time
from win32api import FindExecutable
from os import spawnl, P_NOWAIT
...
pd = "C:\\temp\\test.pdf"
pdbits = os.path.split(pd)
readerexe = FindExecutable(pdbits[1],pdbits[0])
spawnl(P_NOWAIT,readerexe[1],"DUMMY") #I added "DUMMY" to avoid a weird error
time.sleep(2)
s = dde.CreateServer()
s.Create('')
c = dde.CreateConversation(s)
c.ConnectTo('acroview', 'control')
c.Exec('[FilePrintSilent("%s")]' % (pd,))
s.Destroy()
但它在该ConnectTo
行抛出此异常:
dde.error: ConnectTo failed
有人知道如何解决吗?或者有不同的静音打印解决方案?或者在列表中可以提供参考ConnectTo
链接?在网上找不到任何关于它的信息。
使用:Python 2.7、Windows 7、Acrobat Reader 10.0