I posted a question yesterday RE: this same script, and managed to work out an implementation on my own, but this one has me stumped so I implemented a workaround instead. I'd rather NOT keep the workaround, so I'd love some help.
I've written an app in Python to navigate through a number of ZipFile objects to grab a PDF based on user input. My goal was to output that PDF directly to the printer, which seems to be more difficult than at first it seemed. The solution I wanted to use was win32api's ShellExecute, but I'm certainly not sold on it. However, in implementation, I came up against a wall. Here's my error:
def _printPDF(selected_file): win32api.ShellExecute(0, "print", selected_file.name, None, ".", 0) # Should print to my default printer if I don't give it an argument # to redirect output, but I've also tried using the argument to # explicitly print to win32print.GetDefaultPrinter(). Same error>>> _printPDF(filename)pywintypes.error: (31, 'ShellExecute', 'A device attached to the system is not functioning.')The printer is functioning if I simply right-click the file and select "Print" from the contextual menu, but it doesn't want to listen to Python. As a workaround, I've basically just changed my script from _printPDF to _openPDF and changed my ShellExecute call to "open" instead of "print".
I'm planning on using this app on a number of machines in my office, so simply hardcoding a printer won't work. As I mentioned earlier, I'm not against another implementation but this one seems to be the simplest hack to get the file printed. It doesn't have to be particularly robust, but it does have to print to any given Windows machine's default printer.