我正在尝试使用 Python 打印 PDF,而不打开 PDF 查看器应用程序(Adobe、Foxit 等)。我还需要知道打印何时完成(以删除文件)。
Here http://permalink.gmane.org/gmane.comp.python.windows/6558我找到了这个执行:
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
line:
dde.error: ConnectTo failed
有人知道如何解决吗?或者有一个不同的解决方案用于静音打印?或者在列表中可以给出一个链接参考ConnectTo
?在网上找不到任何关于它的信息。
使用:Python 2.7、Windows 7、Acrobat Reader 10.0
我建议你安装GSView http://pages.cs.wisc.edu/~ghost/gsview/get49.htm and GSPrint http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm并支付给gsprint.exe
打印 pdf。
p = subprocess.Popen([r"p:\ath\to\gsprint.exe", "test.pdf"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout
print stderr
我已经在工业标签打印解决方案中使用了它,效果很好。
当。。。的时候gsprint.exe
程序退出(即在调用communicate
),您可以删除该pdf文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)