简体   繁体   中英

Print a file in Python on Windows without opening it

Running the following line of python causes Adobe Acrobat to launch

win32api.ShellExecute(0, "print", "myC.pdf", None, ".", 0)

Adobe is my default PDF viewer. Why is Adobe opening? How can I prevent this from happening?

The script meant to run many times on a slow PC.

I do not understand how print works from ShellExecute . Typing print myC.pdf in the command prompt gives me the error "Unable to initialize device PRN". A little background would be appreciated.

print ing the file at the system level is a command to display the file. Adobe's viewer is the application associated with this file. What are you expecting to happen? If you want to operate on the file with some other application, then you'll have to specify that through a more focused interface.

print is equivalent to the GUI sequence right-clink + Print. The first thing that print does is to open the file; Windows doesn't have a default interface to print a file without opening it normally.

I found you a couple of references that know even more than I do: :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM