Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing PDF files with Python

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)

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

TypeError: an integer is required
like image 303
Mike C. Avatar asked Dec 24 '22 05:12

Mike C.


1 Answers

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()
like image 137
Mike C. Avatar answered Dec 25 '22 18:12

Mike C.