python自动打印pdf_用Python静默打印PDF

使用Python实现PDF无声打印,不启动PDF查看器(如Adobe或Foxit),并想知道打印何时完成以删除文件。尝试使用win32ui、dde等库,但遇到dde.error: ConnectTo failed 的异常。建议使用GSView和GSPrint,通过调用gsprint.exe进行打印,当gsprint.exe退出后,可以安全删除PDF文件。
摘要由CSDN通过智能技术生成

I'm trying to print a PDF with Python, without opening the PDF viewer application (Adobe, Foxit etc.). I need also to know when printing has finished (to delete the file).

Here I found this implementation:

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()

But it throws thi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值