Python File as the Default PDF handler for Windows

Naftali nmichalowsky at gmail.com
Thu Jun 18 21:03:14 EDT 2015


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.

Thank you for responding, Chris:

I may be missing something in your reply, but I am *not* wondering how to associate python with the .pdf file extension. That I know how to do. What I want to know is how from within the program that I've told windows to run when the user clicks on the file --- how to access the file that the user wishes to open. Windows must somehow make that available to my program. How to I access it. Tomorrow, I'll try doing it an looping through the sys.argvs and see what's there. maybe it's a simple as passing a path into the called program.



More information about the Python-list mailing list