使用 Python 打印 PDF 文件 [英] Printing PDF files with Python

查看:114
本文介绍了使用 Python 打印 PDF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Python 2.7 中打开 pdf 文件、打印文件并关闭 Adob​​e Acrobat.

I am trying to open a pdf file, print the file, and close Adobe Acrobat in Python 2.7.

import os

fd = os.startfile("temp.pdf", "print")
os.close(fd)

运行代码后,我在 os.close(fd) 行上收到以下错误:

After running the code, I get the following error on the os.close(fd) line:

TypeError: an integer is required

推荐答案

这是我想出的解决方案:

Here's the solution that I came up with:

    os.startfile("temp.pdf", "print")
    sleep(5)
    for p in psutil.process_iter(): #Close Acrobat after printing the PDF
        if 'AcroRd' in str(p):
            p.kill()

这篇关于使用 Python 打印 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆