2

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.

peteey
  • 420
  • 4
  • 14

1 Answers1

0

printing 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: :-)

Community
  • 1
  • 1
Prune
  • 76,765
  • 14
  • 60
  • 81
  • I expect the command to print the file myC.pdf to a label maker. The label does print due to this command. Is this command telling Adobe to print the file? – peteey Mar 30 '17 at 15:25
  • Ah ... so you get the desired effect; your only problem is that it also displays the file on the console? – Prune Mar 30 '17 at 15:35
  • @petEEy: exactly. As phyton has no knowledge of the file contents (and isn't able to handle it on it's own), it _needs_ the proper application to read (and print) it. – Stephan Mar 30 '17 at 15:44