首页 > 解决方案 > 使用 Python 打印 PDF 文件

问题描述

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

import os

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

运行代码后,出现以下错误os.close(fd)

TypeError: an integer is required

标签: pythonpython-2.7

解决方案


这是我想出的解决方案:

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

推荐阅读