On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote: > Long time lurker. > > I'm looking to register a python script as the default pdf reader for > windows. I assume I can just register the .py in the section windows section > for registering default handlers, but I'm wondering how to access the file > from within the program. > > The issue is this: > > We have Java application that outputs user uploaded pdf files. It does this > simply by instructing windows to open the downloaded pdf file and windows > takes it from there. The data entry person will view the pdf and usually > upload it into another part of the system. Problem is the second leg of the > system modifies the pdf, and thus crashes when the pdf is protected against > writing. Data entry make use of a program to unlock them as needed but it is > an extra step and it only comes to their awareness after their client crashes > on the locked pdf (because it doesn't make sense to check them proactively. > > I cannot change the Java system. > > What I want to do is write a pdf handler to handle windows open instruction. > In the script I would run a command line pdf unlocker on the file and open > the unlocked file with adobe (or the like). > > I've googled and though I get tons of 'how to open pdf from a python script' > I haven't found anything describing how to write and set up my python program > to deal with the pdf hand-off from the OS.
Just to update, you are correct, Chris, the file short name is passed into sys.argv. didn't need to add anything to the path. But a gotcha -- Windows didn't like my .py, clicking on the pdf causes Windows to complain about 'file x' is not a valid windows executable. I didn't research it so cant speak definitely, but converting the .py to a py2exe correlated with that complaint going away. In the end, though since, making any changes to the program required redoing the py2exe and since this is to be running on a colleagues machine, I ended up putting the handler commands into a .bat file. My hunch is that it's faster that way, too. -- https://mail.python.org/mailman/listinfo/python-list